⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 elgamalsign.java

📁 ElGamal method is an aymetric method to crypt message. You can use ElGamal to crypt the key session
💻 JAVA
字号:
package elgamal;import java.math.BigInteger;import java.util.Random;public class ElGamalSign {    private BigInteger r;    private BigInteger s;    private static final BigInteger UN = BigInteger.ONE;    public ElGamalSign(Parameter params,PrivateKey x,byte[]M){                sha256 sh=new sha256(M);        int[]sha=sh.getHash();        byte[]hash=new byte[32];        int i=0;        for(int j=0;j<8;j++){            hash[i++]=(byte)(sha[j] & 0xFF);            hash[i++]=(byte)((sha[j]>>>8) & 0xFF);            hash[i++]=(byte)((sha[j]>>>16) & 0xFF);            hash[i++]=(byte)((sha[j]>>>24) & 0xFF);        }        BigInteger m=new BigInteger(hash);        BigInteger k=new BigInteger(params.getP().bitLength()-1,new Random());        BigInteger p1=params.getP().subtract(UN);        while(!k.gcd(p1).equals(UN)){            k=new BigInteger(params.getP().bitLength()-1,new Random());        }        r=params.getG().modPow(k,params.getP());        k=k.modInverse(p1);        s=k.multiply(m.subtract(r.multiply(x.getX()))).mod(p1);    }        public BigInteger getR(){        return r;    }    public BigInteger getS(){        return s;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -