Search in sources :

Example 1 with GOST3410PrivateKeyParameters

use of com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters in project LinLong-Java by zhenwei1108.

the class GOST3410KeyPairGenerator method generateKeyPair.

public AsymmetricCipherKeyPair generateKeyPair() {
    BigInteger p, q, a, x, y;
    GOST3410Parameters GOST3410Params = param.getParameters();
    SecureRandom random = param.getRandom();
    q = GOST3410Params.getQ();
    p = GOST3410Params.getP();
    a = GOST3410Params.getA();
    int minWeight = 64;
    for (; ; ) {
        x = BigIntegers.createRandomBigInteger(256, random);
        if (x.signum() < 1 || x.compareTo(q) >= 0) {
            continue;
        }
        if (WNafUtil.getNafWeight(x) < minWeight) {
            continue;
        }
        break;
    }
    // 
    // calculate the public key.
    // 
    y = a.modPow(x, p);
    return new AsymmetricCipherKeyPair(new GOST3410PublicKeyParameters(y, GOST3410Params), new GOST3410PrivateKeyParameters(x, GOST3410Params));
}
Also used : GOST3410Parameters(com.github.zhenwei.core.crypto.params.GOST3410Parameters) GOST3410PrivateKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters) BigInteger(java.math.BigInteger) SecureRandom(java.security.SecureRandom) GOST3410PublicKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 2 with GOST3410PrivateKeyParameters

use of com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters in project LinLong-Java by zhenwei1108.

the class KeyPairGeneratorSpi method generateKeyPair.

public KeyPair generateKeyPair() {
    if (!initialised) {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), CryptoServicesRegistrar.getSecureRandom());
    }
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters) pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters) pair.getPrivate();
    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
Also used : KeyPair(java.security.KeyPair) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair) GOST3410PrivateKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters) GOST3410PublicKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters) GOST3410ParameterSpec(com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec) AsymmetricCipherKeyPair(com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)

Example 3 with GOST3410PrivateKeyParameters

use of com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters in project LinLong-Java by zhenwei1108.

the class GOST3410Util method generatePrivateKeyParameter.

public static AsymmetricKeyParameter generatePrivateKeyParameter(PrivateKey key) throws InvalidKeyException {
    if (key instanceof GOST3410PrivateKey) {
        GOST3410PrivateKey k = (GOST3410PrivateKey) key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();
        return new GOST3410PrivateKeyParameters(k.getX(), new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }
    throw new InvalidKeyException("can't identify GOST3410 private key.");
}
Also used : GOST3410Parameters(com.github.zhenwei.core.crypto.params.GOST3410Parameters) GOST3410PrivateKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters) InvalidKeyException(java.security.InvalidKeyException) GOST3410PrivateKey(com.github.zhenwei.provider.jce.interfaces.GOST3410PrivateKey) GOST3410PublicKeyParameterSetSpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)

Aggregations

GOST3410PrivateKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters)3 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)2 GOST3410Parameters (com.github.zhenwei.core.crypto.params.GOST3410Parameters)2 GOST3410PublicKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters)2 GOST3410PrivateKey (com.github.zhenwei.provider.jce.interfaces.GOST3410PrivateKey)1 GOST3410ParameterSpec (com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec)1 GOST3410PublicKeyParameterSetSpec (com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)1 BigInteger (java.math.BigInteger)1 InvalidKeyException (java.security.InvalidKeyException)1 KeyPair (java.security.KeyPair)1 SecureRandom (java.security.SecureRandom)1