bc-java
bc-java copied to clipboard
How to implement ECIESwithSHA256andAES-ECB
Hi, I am trying to implement the following nodejs code in java, but I found that ECIESwithSHA256andAES-ECB is not provided by BouncyCastle. How can I implement this algorithm?
// https://www.npmjs.com/package/standard-ecies
// option parameter is optional, all options are optional except iv,
// when symmetric cipher is not in ecb mode, iv option must be offered.
// default option
const options = {
hashName: 'sha256',
hashLength: 32,
macName: 'sha256',
macLength: 32,
curveName: 'secp256k1',
symmetricCypherName: 'aes-128-ecb',
iv: null,
// iv is used in symmetric cipher, set null if the cipher does not need an
// initialization vector (e.g. a cipher in ecb mode). Set undefined if you
// want to use deprecated createCipheriv / createDecipher / EVP_BytesToKey
keyFormat: 'uncompressed',
s1: null, // optional shared information1
s2: null // optional shared information2
}
const ecdh = crypto.createECDH(options.curveName);
ecdh.generateKeys();
const plainText = Buffer.from('hello world');
const encryptedText = ecies.encrypt(ecdh.getPublicKey(), plainText, options);
const decryptedText = ecies.decrypt(ecdh, encryptedText, options);
assert(plainText.toString('hex') == decryptedText.toString('hex'));