mirror of
https://github.com/openpgpjs/openpgpjs.git
synced 2026-03-07 09:31:36 +00:00
Use native Node crypto for RSA encryption (#1006)
This commit is contained in:
committed by
Daniel Huigens
parent
495fe1091c
commit
45c2e67624
@@ -356,38 +356,26 @@ describe('API functional testing', function() {
|
||||
|
||||
it('Asymmetric using RSA with eme_pkcs1 padding', function () {
|
||||
const symmKey = util.Uint8Array_to_str(crypto.generateSessionKey('aes256'));
|
||||
return crypto.pkcs1.eme.encode(symmKey, RSApubMPIs[0].byteLength()).then(RSAUnencryptedData => {
|
||||
const RSAUnencryptedMPI = new openpgp.MPI(RSAUnencryptedData);
|
||||
return crypto.publicKeyEncrypt(1, RSApubMPIs, RSAUnencryptedMPI);
|
||||
}).then(RSAEncryptedData => {
|
||||
|
||||
crypto.publicKeyEncrypt(1, RSApubMPIs, symmKey).then(RSAEncryptedData => {
|
||||
return crypto.publicKeyDecrypt(
|
||||
1, RSApubMPIs.concat(RSAsecMPIs), RSAEncryptedData
|
||||
).then(data => {
|
||||
data = new openpgp.MPI(data).write();
|
||||
data = util.Uint8Array_to_str(data.subarray(2, data.length));
|
||||
|
||||
const result = crypto.pkcs1.eme.decode(data, RSApubMPIs[0].byteLength());
|
||||
expect(result).to.equal(symmKey);
|
||||
expect(data).to.equal(symmKey);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('Asymmetric using Elgamal with eme_pkcs1 padding', function () {
|
||||
const symmKey = util.Uint8Array_to_str(crypto.generateSessionKey('aes256'));
|
||||
return crypto.pkcs1.eme.encode(symmKey, ElgamalpubMPIs[0].byteLength()).then(ElgamalUnencryptedData => {
|
||||
const ElgamalUnencryptedMPI = new openpgp.MPI(ElgamalUnencryptedData);
|
||||
return crypto.publicKeyEncrypt(16, ElgamalpubMPIs, ElgamalUnencryptedMPI);
|
||||
}).then(ElgamalEncryptedData => {
|
||||
|
||||
crypto.publicKeyEncrypt(16, ElgamalpubMPIs, symmKey).then(ElgamalEncryptedData => {
|
||||
return crypto.publicKeyDecrypt(
|
||||
16, ElgamalpubMPIs.concat(ElgamalsecMPIs), ElgamalEncryptedData
|
||||
).then(data => {
|
||||
data = new openpgp.MPI(data).write();
|
||||
data = util.Uint8Array_to_str(data.subarray(2, data.length));
|
||||
|
||||
const result = crypto.pkcs1.eme.decode(data, ElgamalpubMPIs[0].byteLength());
|
||||
expect(result).to.equal(symmKey);
|
||||
expect(data).to.equal(symmKey);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user