Search in sources :

Example 1 with GOST3410ParameterSpec

use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec 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 2 with GOST3410ParameterSpec

use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.

the class AlgorithmParameterGeneratorSpi method engineGenerateParameters.

protected AlgorithmParameters engineGenerateParameters() {
    GOST3410ParametersGenerator pGen = new GOST3410ParametersGenerator();
    if (random != null) {
        pGen.init(strength, 2, random);
    } else {
        pGen.init(strength, 2, CryptoServicesRegistrar.getSecureRandom());
    }
    GOST3410Parameters p = pGen.generateParameters();
    AlgorithmParameters params;
    try {
        params = createParametersInstance("GOST3410");
        params.init(new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec(p.getP(), p.getQ(), p.getA())));
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage());
    }
    return params;
}
Also used : GOST3410Parameters(com.github.zhenwei.core.crypto.params.GOST3410Parameters) GOST3410ParametersGenerator(com.github.zhenwei.core.crypto.generators.GOST3410ParametersGenerator) GOST3410ParameterSpec(com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) AlgorithmParameters(java.security.AlgorithmParameters) GOST3410PublicKeyParameterSetSpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)

Example 3 with GOST3410ParameterSpec

use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.

the class BCGOST3410PrivateKey method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    String publicKeyParamSetOID = (String) in.readObject();
    if (publicKeyParamSetOID != null) {
        this.gost3410Spec = new GOST3410ParameterSpec(publicKeyParamSetOID, (String) in.readObject(), (String) in.readObject());
    } else {
        this.gost3410Spec = new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec((BigInteger) in.readObject(), (BigInteger) in.readObject(), (BigInteger) in.readObject()));
        in.readObject();
        in.readObject();
    }
    this.attrCarrier = new PKCS12BagAttributeCarrierImpl();
}
Also used : PKCS12BagAttributeCarrierImpl(com.github.zhenwei.provider.jcajce.provider.asymmetric.util.PKCS12BagAttributeCarrierImpl) ASN1OctetString(com.github.zhenwei.core.asn1.ASN1OctetString) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) GOST3410ParameterSpec(com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec) GOST3410PublicKeyParameterSetSpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)

Example 4 with GOST3410ParameterSpec

use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.

the class BCGOST3410PublicKey method readObject.

private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    String publicKeyParamSetOID = (String) in.readObject();
    if (publicKeyParamSetOID != null) {
        this.gost3410Spec = new GOST3410ParameterSpec(publicKeyParamSetOID, (String) in.readObject(), (String) in.readObject());
    } else {
        this.gost3410Spec = new GOST3410ParameterSpec(new GOST3410PublicKeyParameterSetSpec((BigInteger) in.readObject(), (BigInteger) in.readObject(), (BigInteger) in.readObject()));
        in.readObject();
        in.readObject();
    }
}
Also used : DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) GOST3410ParameterSpec(com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec) GOST3410PublicKeyParameterSetSpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)

Example 5 with GOST3410ParameterSpec

use of com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec in project LinLong-Java by zhenwei1108.

the class BCGOST3410PublicKey method getEncoded.

public byte[] getEncoded() {
    SubjectPublicKeyInfo info;
    byte[] keyEnc = this.getY().toByteArray();
    byte[] keyBytes;
    if (keyEnc[0] == 0) {
        keyBytes = new byte[keyEnc.length - 1];
    } else {
        keyBytes = new byte[keyEnc.length];
    }
    for (int i = 0; i != keyBytes.length; i++) {
        // must be little endian
        keyBytes[i] = keyEnc[keyEnc.length - 1 - i];
    }
    try {
        if (gost3410Spec instanceof GOST3410ParameterSpec) {
            if (gost3410Spec.getEncryptionParamSetOID() != null) {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getEncryptionParamSetOID()))), new DEROctetString(keyBytes));
            } else {
                info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94, new GOST3410PublicKeyAlgParameters(new ASN1ObjectIdentifier(gost3410Spec.getPublicKeyParamSetOID()), new ASN1ObjectIdentifier(gost3410Spec.getDigestParamSetOID()))), new DEROctetString(keyBytes));
            }
        } else {
            info = new SubjectPublicKeyInfo(new AlgorithmIdentifier(CryptoProObjectIdentifiers.gostR3410_94), new DEROctetString(keyBytes));
        }
        return KeyUtil.getEncodedSubjectPublicKeyInfo(info);
    } catch (IOException e) {
        return null;
    }
}
Also used : GOST3410PublicKeyAlgParameters(com.github.zhenwei.core.asn1.cryptopro.GOST3410PublicKeyAlgParameters) IOException(java.io.IOException) GOST3410ParameterSpec(com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec) SubjectPublicKeyInfo(com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo) ASN1ObjectIdentifier(com.github.zhenwei.core.asn1.ASN1ObjectIdentifier) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)

Aggregations

GOST3410ParameterSpec (com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec)6 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)4 GOST3410PublicKeyParameterSetSpec (com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)3 ASN1ObjectIdentifier (com.github.zhenwei.core.asn1.ASN1ObjectIdentifier)2 GOST3410PublicKeyAlgParameters (com.github.zhenwei.core.asn1.cryptopro.GOST3410PublicKeyAlgParameters)2 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)2 IOException (java.io.IOException)2 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)1 PrivateKeyInfo (com.github.zhenwei.core.asn1.pkcs.PrivateKeyInfo)1 SubjectPublicKeyInfo (com.github.zhenwei.core.asn1.x509.SubjectPublicKeyInfo)1 AsymmetricCipherKeyPair (com.github.zhenwei.core.crypto.AsymmetricCipherKeyPair)1 GOST3410ParametersGenerator (com.github.zhenwei.core.crypto.generators.GOST3410ParametersGenerator)1 GOST3410Parameters (com.github.zhenwei.core.crypto.params.GOST3410Parameters)1 GOST3410PrivateKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters)1 GOST3410PublicKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters)1 PKCS12BagAttributeCarrierImpl (com.github.zhenwei.provider.jcajce.provider.asymmetric.util.PKCS12BagAttributeCarrierImpl)1 AlgorithmParameters (java.security.AlgorithmParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 KeyPair (java.security.KeyPair)1