Socket
Socket
Sign inDemoInstall

paillier-bigint

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

paillier-bigint - npm Package Compare versions

Comparing version 3.0.3 to 3.0.4

2

package.json
{
"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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc