You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi there,
First thanks for the amazing effort in this pakcage, it's really saving my day.
Well here seems to be some problems with my code.
what I can do:
import a privateKey
use it to generate a new publicKey, and de/encrypt works like a charming.
what I want:
import the publicKey and the privateKey at the same time
use them to de/encrypt, don't have to generate a new one
The code under blow is as far as I can get. It's a bit of ugly, please don't laugh at me for me being a rookie.
varkeyUtils=require('js-crypto-key-utils');vareccrypto=require("eccrypto");varprivKeyA=`-----BEGIN PRIVATE KEY-----MIGHAgEAMBMGByqGSM49AgEGCCqGSM49AwEHBG0wawIBAQQgYYZNfKK0D3KJUE45m7mBYQsH+iOu3IuzwK2W21/3lQChRANCAAT0SdzISybvGSWhwokYCndUAYwSPIkELuvZ2y9CBGO6PGGRvWJTvklrMfaALSxFlcXpdSfnB5ieBrht+qspmGBC-----END PRIVATE KEY-----`;varpubKeyA=`-----BEGIN PUBLIC KEY-----MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAE9EncyEsm7xklocKJGAp3VAGMEjyJBC7r2dsvQgRjujxhkb1iU75JazH2gC0sRZXF6XUn5weYnga4bfqrKZhgQg==-----END PUBLIC KEY-----`;constpubKeyObjFromPemA=newkeyUtils.Key('pem',pubKeyA);// console.log(pubKeyObjFromPemA);constprvKeyObjFromPemA=newkeyUtils.Key('pem',privKeyA);// console.log(prvKeyObjFromPemA);asyncfunctionfoo(){letprvKeyJWKA=awaitprvKeyObjFromPemA.export('oct');letpubKeyJWKA=awaitpubKeyObjFromPemA.export('oct');// console.log(prvKeyJWKA);// console.log(pubKeyJWKA);// let pubAHex = Array.prototype.map.call(pubKeyJWKA, x => ('00' + x.toString(16)).slice(-2)).join('');varprivateKeyA=Buffer.from(prvKeyJWKA);varpublicKeyA=Buffer.from(pubKeyJWKA);console.log(publicKeyA.toString('hex'));letpubAHex=Array.prototype.map.call(publicKeyA,x=>('00'+x.toString(16)).slice(-2)).join('');console.log(pubAHex);publicKeyA=eccrypto.getPublic(privateKeyA);console.log(publicKeyA.toString('hex'));// Encrypting the message for A.letencrypted=awaiteccrypto.encrypt(publicKeyA,Buffer.from("msg to a asdasdasdasd"));console.log(encrypted.ciphertext.toString());letplaintext=awaiteccrypto.decrypt(privateKeyA,encrypted);console.log(plaintext.toString())}foo();
and here is what I got from the last run :
04f449dcc84b26ef1925a1c289180a7754018c123c89042eebd9db2f420463ba3c6191bd6253be496b31f6802d2c4595c5e97527e707989e06b86dfaab29986042
04f449dcc84b26ef1925a1c289180a7754018c123c89042eebd9db2f420463ba3c6191bd6253be496b31f6802d2c4595c5e97527e707989e06b86dfaab29986042
04f8d2d188ba947c54af0607e689258f2bdd7ab99027752975915b1baf56a9bf8c35c23fe2b0dc53999c60a963b317eabcd0bbdf612359906737d1173a1d386e0c
������ӆ�s������>�w�$���v�_�O)�d
msg to a asdasdasdasd
I really hope you may help me with this issue. Also if it's not happening by some reason, that's ok, I can just save another publicKey for the encryption using.
Thanks again for your time,
David
The text was updated successfully, but these errors were encountered:
I'm not sure I understand the problem, if you already have the private key, why not just generate the public key? It's deterministic. Are you sure that pem public key is correct?
and if I want to use the ecc encrypt/decrypt, I will have to generate a new ecc-publicKey from the privateKey , which I already have a ecdsa-publicKey in hand.
So now I have ecdsaPrivateKey, ecdsaPublicKey and eccPublicKey.
Can I just use the ecdsaPublicKey in ecc crypto instead of generating a new eccPub?
Hi there,
First thanks for the amazing effort in this pakcage, it's really saving my day.
Well here seems to be some problems with my code.
The code under blow is as far as I can get. It's a bit of ugly, please don't laugh at me for me being a rookie.
and here is what I got from the last run :
04f449dcc84b26ef1925a1c289180a7754018c123c89042eebd9db2f420463ba3c6191bd6253be496b31f6802d2c4595c5e97527e707989e06b86dfaab29986042 04f449dcc84b26ef1925a1c289180a7754018c123c89042eebd9db2f420463ba3c6191bd6253be496b31f6802d2c4595c5e97527e707989e06b86dfaab29986042 04f8d2d188ba947c54af0607e689258f2bdd7ab99027752975915b1baf56a9bf8c35c23fe2b0dc53999c60a963b317eabcd0bbdf612359906737d1173a1d386e0c ������ӆ�s������>�w�$���v�_�O)�d msg to a asdasdasdasd
I really hope you may help me with this issue. Also if it's not happening by some reason, that's ok, I can just save another publicKey for the encryption using.
Thanks again for your time,
David
The text was updated successfully, but these errors were encountered: