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

📄 rsablindingfactorgenerator.java

📁 kmlnjlkj nlkjlkjkljl okopokipoipo oipipipo i
💻 JAVA
字号:
package org.bouncycastle.crypto.generators;import org.bouncycastle.crypto.CipherParameters;import org.bouncycastle.crypto.params.ParametersWithRandom;import org.bouncycastle.crypto.params.RSAKeyParameters;import org.bouncycastle.crypto.params.RSAPrivateCrtKeyParameters;import java.math.BigInteger;import java.security.SecureRandom;/** * Generate a random factor suitable for use with RSA blind signatures * as outlined in Chaum's blinding and unblinding as outlined in * "Handbook of Applied Cryptography", page 475. */public class RSABlindingFactorGenerator{    private static BigInteger ZERO = BigInteger.valueOf(0);    private static BigInteger ONE = BigInteger.valueOf(1);    private RSAKeyParameters key;    private SecureRandom random;    /**     * Initialise the factor generator     *     * @param param the necessary RSA key parameters.     */    public void init(        CipherParameters param)    {        if (param instanceof ParametersWithRandom)        {            ParametersWithRandom rParam = (ParametersWithRandom)param;            key = (RSAKeyParameters)rParam.getParameters();            random = rParam.getRandom();        }        else        {            key = (RSAKeyParameters)param;            random = new SecureRandom();        }        if (key instanceof RSAPrivateCrtKeyParameters)        {            throw new IllegalArgumentException("generator requires RSA public key");        }    }    /**     * Generate a suitable blind factor for the public key the generator was initialised with.     *     * @return a random blind factor     */    public BigInteger generateBlindingFactor()    {        if (key == null)        {            throw new IllegalStateException("generator not initialised");        }        BigInteger m = key.getModulus();        int length = m.bitLength() - 1; // must be less than m.bitLength()        BigInteger factor;        BigInteger gcd;        do        {            factor = new BigInteger(length, random);            gcd = factor.gcd(m);        }        while (factor.equals(ZERO) || factor.equals(ONE) || !gcd.equals(ONE));        return factor;    }}

⌨️ 快捷键说明

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