paillier-bigint
Advanced tools
Comparing version 3.0.3 to 3.0.4
{ | ||
"name": "paillier-bigint", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "An implementation of the Paillier cryptosystem using native JS (ECMA 2020) implementation of BigInt", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -114,26 +114,26 @@ [![JavaScript Style Guide](https://cdn.rawgit.com/standard/standard/master/badge.svg)](https://github.com/standard/standard) | ||
```javascript | ||
async function paillierTest() { | ||
// (asynchronous) creation of a random private, public key pair for the Paillier cryptosystem | ||
const {publicKey, privateKey} = await paillierBigint.generateRandomKeys(3072) | ||
async function paillierTest () { | ||
// (asynchronous) creation of a random private, public key pair for the Paillier cryptosystem | ||
const { publicKey, privateKey } = await paillierBigint.generateRandomKeys(3072) | ||
// optionally, you can create your public/private keys from known parameters | ||
const publicKey = new paillierBigint.PublicKey(n, g) | ||
const privateKey = new paillierBigint.PrivateKey(lambda, mu, publicKey) | ||
// Optionally, you can create your public/private keys from known parameters | ||
// const publicKey = new paillierBigint.PublicKey(n, g) | ||
// const privateKey = new paillierBigint.PrivateKey(lambda, mu, publicKey) | ||
// encrypt m | ||
let c = publicKey.encrypt(m) | ||
const m1 = 12345678901234567890n | ||
const m2 = 5n | ||
// decrypt c | ||
let d = privateKey.decrypt(c) | ||
// encryption/decryption | ||
const c1 = publicKey.encrypt(m1) | ||
console.log(privateKey.decrypt(c1)) // 12345678901234567890n | ||
// homomorphic addition of two ciphertexts (encrypted numbers) | ||
let c1 = publicKey.encrypt(m1) | ||
let c2 = publicKey.encrypt(m2) | ||
let encryptedSum = publicKey.addition(c1, c2) | ||
let sum = privateKey.decrypt(encryptedSum) // m1 + m2 | ||
// homomorphic addition of two ciphertexts (encrypted numbers) | ||
const c2 = publicKey.encrypt(m2) | ||
const encryptedSum = publicKey.addition(c1, c2) | ||
console.log(privateKey.decrypt(encryptedSum)) // m1 + m2 = 12345678901234567895n | ||
// multiplication by k | ||
let c1 = publicKey.encrypt(m1) | ||
let encryptedMul = publicKey.multiply(c1, k) | ||
let mul = privateKey.decrypt(encryptedMul) // k · m1 | ||
// multiplication by k | ||
const k = 10n | ||
const encryptedMul = publicKey.multiply(c1, k) | ||
console.log(privateKey.decrypt(encryptedMul)) // k · m1 = 123456789012345678900n | ||
} | ||
@@ -144,2 +144,5 @@ paillierTest() | ||
> Consider using [bigint-conversion](https://github.com/juanelas/bigint-conversion) if you need to convert from/to bigint to/from unicode text, hex, buffer. | ||
## API reference documentation | ||
@@ -146,0 +149,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
45142
338
0