Cryptographic javascript-functions for ethereum and tutorials to use them with web3js and solidity
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.
 
 
eth-crypto/dist/es/decrypt-with-private-key.js

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();
});
}