pyca / cryptography

cryptography is a package designed to expose cryptographic primitives and recipes to Python developers.
https://cryptography.io
Other
6.6k stars 1.51k forks source link

How to set the Private-Key without generate_private_key? #7508

Closed hatem-amer closed 2 years ago

hatem-amer commented 2 years ago

In Node Js this done as follows:

const crypto = require('crypto');
const ece = require('http_ece');

const dh = crypto.createECDH('prime256v1');
dh.setPrivateKey("d25a7249abac3beae6d03e0441867de762ea4cfc51e5c202a3fc0a45486d1f94", 'hex');
const params = {
    version: 'aes128gcm',
    authSecret: "a7omShAT1ycPQqu9UHaS6Q",
    privateKey: dh,
};
const buf = Buffer.from(array2, 'hex'); 
const decrypted = ece.decrypt(buf, params);
console.log(decrypted.toString());
reaperhulk commented 2 years ago

You can load private keys via load_pem_private_key and load_der_private_key. If you have raw key components you can also use the Numbers classes, although that requires more expertise to use properly.