blockchainethereumsmart-contractssoliditytutorialdappweb3ethtruffleweb3jstransactionsigntransactionsignaturesign-datasignpublickeyprivatekeyethereum-identityencryptioncipher
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
686 B
18 lines
686 B
import { decrypt } from 'eccrypto';
|
|
import { parse } from './cipher';
|
|
import { removeLeading0x } from './util';
|
|
export function decryptWithPrivateKey(privateKey, encrypted) {
|
|
encrypted = parse(encrypted);
|
|
|
|
// remove trailing '0x' from privateKey
|
|
var twoStripped = removeLeading0x(privateKey);
|
|
var encryptedBuffer = {
|
|
iv: Buffer.from(encrypted.iv, 'hex'),
|
|
ephemPublicKey: Buffer.from(encrypted.ephemPublicKey, 'hex'),
|
|
ciphertext: Buffer.from(encrypted.ciphertext, 'hex'),
|
|
mac: Buffer.from(encrypted.mac, 'hex')
|
|
};
|
|
return decrypt(Buffer.from(twoStripped, 'hex'), encryptedBuffer).then(function (decryptedBuffer) {
|
|
return decryptedBuffer.toString();
|
|
});
|
|
} |