《数据流通关键技术》之一:同态加密.md

同态加密


同态加法:输入密文1 + 输入密文2 = 加密结果 (这个结果解密后 = 明文1 + 明文2)

百度百科定义: 加法同态,如果存在有效算法⊕,E(x+y)=E(x)⊕E(y)或者 x+y=D(E(x)⊕E(y))成立,并且不泄漏 x 和 y

同态算法实现有几种

在这里插入图片描述

参考资料


paillier同态加密算法的java实现

import java.math.*;

import java.util.*;

 

/**

 * Paillier Cryptosystem <br>

 * <br>

 * References: <br>

 * [1] Pascal Paillier,

 * "Public-Key Cryptosystems Based on Composite Degree Residuosity Classes,"

 * EUROCRYPT'99. URL:

 * <a href="http://www.gemplus.com/smart/rd/publications/pdf/Pai99pai.pdf">http:

 * //www.gemplus.com/smart/rd/publications/pdf/Pai99pai.pdf</a><br>

 *

 * [2] Paillier cryptosystem from Wikipedia. URL:

 * <a href="http://en.wikipedia.org/wiki/Paillier_cryptosystem">http://en.

 * wikipedia.org/wiki/Paillier_cryptosystem</a>

 * 

 * @author Kun Liu (kunliu1@cs.umbc.edu)

 * @version 1.0

 */

public class Paillier {
   

 

 /**

  * p and q are two large primes. lambda = lcm(p-1, q-1) =

  * (p-1)*(q-1)/gcd(p-1, q-1).

  */

 private BigInteger p, q, lambda;

 /**

  * n = p*q, where p and q are two large primes.

  */

 public BigInteger n;

 /**

  * nsquare = n*n

  */

 public BigInteger nsquare;

 /**

  * a random integer in Z*_{n^2} where gcd (L(g^lambda mod n^2), n) = 1.

  */

 private BigInteger g;

 /**

  * number of bits of modulus

  */

 private int bitLength;

 

 /**

  * Constructs an instance of the Paillier cryptosystem.

  * 

  * @param bitLengthVal

  * number of bits of modulus

  * @param certainty

  * The probability that the new BigInteger represents a prime

  * number will exceed (1 - 2^(-certainty)). The execution time of

  * this constructor is proportional to the value of this

  * parameter.

  */

 public Paillier(int bitLengthVal, int certainty) {
   

  KeyGeneration(bitLengthVal, certainty);

 }

 

 /**

  * Constructs an instance of the Paillier cryptosystem with 512 bits of

  * modulus and at least 1-2^(-64) certainty of primes generation.

  */

 public Paillier() {
   

  KeyGeneration(512, 64);

 }

 

 /**

  * Sets up the public key and private key.

  * 

  * @param bitLengthVal

  * number of bits of modulus.

  * @param certainty

  * The probability that the new BigInteger represents a prime

  * number will exceed (1 - 2^(-certainty)). The execution time of

  * this constructor is proportional to the value of this

  * parameter.

  */

 public void KeyGeneration(int bitLengthVal, int certainty) {
   

  bitLength = bitLengthVal;

  /*

   * Constructs two randomly generated positive BigIntegers that are

   * probably prime, with the specified bitLength and certainty.

   */

  p = new BigInteger(bitLength / 2, certainty, new Random());

  q = new BigInteger(bitLength / 2, certainty, new Random());

 

  n = p.multiply(q);

  nsquare = n.multiply(n);

 

  g = new BigInteger("2");

  lambda = p.subtract(BigInteger.ONE).multiply(q.subtract(BigInteger.ONE)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值