Giter Club home page Giter Club logo

javallier's Introduction

Build Status Javadocs

javallier

A Java library for Paillier partially homomorphic encryption based on python-paillier.

The homomorphic properties of the paillier cryptosystem are:

  • Encrypted numbers can be multiplied by a non encrypted scalar.
  • Encrypted numbers can be added together.
  • Encrypted numbers can be added to non encrypted scalars.

To use the library add the following dependency to your SBT configuration:

libraryDependencies += "com.n1analytics" % "javallier_2.10" % "0.6.0"

Example usages are provided in the /examples source directory. A benchmarking script can be found in /benchmark.

Build

Compile the library:

$ sbt compile

Create a jar file:

$ sbt package

Run all tests with sbt:

$ sbt test

Or run just fast tests:

$ ./test-fast.sh

Command Line Tool

A small command line tool has been created to wrap the javallier library.

Use the javallier cli tool to:

  • generate and serialize key pairs (of different key sizes)
  • encrypt and serialize signed floating point numbers given a public key
  • add two encrypted numbers together
  • add an encrypted number to a plaintext number
  • multiply an encrypted number by a plaintext number
  • decrypt an encrypted number given the private key

Build the javallier CLI tool:

sbt assembly

This creates a javallier.jar jar file in:

./target/scala-2.10

To run it:

java -jar javallier.jar <COMMAND>  

Alternatively you can run directly with sbt:

sbt "runMain com.n1analytics.paillier.cli.Main"

Example CLI session

$ java -jar javallier.jar genpkey --keysize 256 -m "Example keypair" examplekey.priv
$ cat examplekey.priv | python -m json.tool
{
    "kty": "DAJ",
    "key_ops": [
        "decrypt"
    ],
    "pub": {
        "alg": "PAI-GN1",
        "kty": "DAJ",
        "kid": "Example keypair",
        "n": "AI9TjNmoL7p3j_D-RNK5AJQC1uDMtVvdy0MNi6ctj6Xn",
        "key_ops": [
            "encrypt"
        ]
    },
    "kid": "Example keypair",
    "lambda": "AI9TjNmoL7p3j_D-RNK5AJJ3odV_yUj39nLtFBMcrsoQ",
    "mu": "MDo136LqeN-R5W4kT2azGc6Y-cD77f6r_B6zncj48Eo"
}


$ java -jar javallier.jar extract examplekey.priv examplekey.pub
$ java -jar javallier.jar encrypt examplekey.pub "12" -o encA.json
$ java -jar javallier.jar encrypt examplekey.pub "8" -o encB.json
$ java -jar javallier.jar addenc examplekey.pub encA.json encB.json -o encC.json
$ java -jar javallier.jar decrypt examplekey.priv encC.json
20.0
$ java -jar javallier.jar add -o encD.json examplekey.pub encA.json 12
$ java -jar javallier.jar decrypt examplekey.priv encD.json
24.0

Releases

Releases will be signed by Brian Thorne with the PGP key 22AD F3BF C183 47DE

Creating a release

Update the version in build.sbt using semantic versioning. Update the CHANGELOG, git tag the new release.

Ensure you have sonatype credentials in ~/.sbt/0.13/sonatype.sbt, and install the pgp plugin (~/.sbt/0.13/plugins/pgp.sbt). Run sbt publishSigned, then visit the staging repositories of sonatype. Close the staging repository which will allow you to move to the release channel. Once you have successfully closed the staging repository, you can release it.

For more information:

Limitation

Adding two encrypted numbers where the exponents differs wildly may result in overflow in the EncryptedNumber domain. The addition result can be successfully decrypted and decoded but the computation result is incorrect. Current implementation does not detect such overflow.

javallier's People

Contributors

hardbyte avatar wilko77 avatar mpnd avatar gusmith avatar tiantianwdy avatar maxott avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.