Search in sources :

Example 1 with GOST3410PublicKeyParameterSetSpec

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

the class GOST3410Util method generatePublicKeyParameter.

public static AsymmetricKeyParameter generatePublicKeyParameter(PublicKey key) throws InvalidKeyException {
    if (key instanceof GOST3410PublicKey) {
        GOST3410PublicKey k = (GOST3410PublicKey) key;
        GOST3410PublicKeyParameterSetSpec p = k.getParameters().getPublicKeyParameters();
        return new GOST3410PublicKeyParameters(k.getY(), new GOST3410Parameters(p.getP(), p.getQ(), p.getA()));
    }
    throw new InvalidKeyException("can't identify GOST3410 public key: " + key.getClass().getName());
}
Also used : GOST3410Parameters(com.github.zhenwei.core.crypto.params.GOST3410Parameters) GOST3410PublicKey(com.github.zhenwei.provider.jce.interfaces.GOST3410PublicKey) GOST3410PublicKeyParameters(com.github.zhenwei.core.crypto.params.GOST3410PublicKeyParameters) InvalidKeyException(java.security.InvalidKeyException) GOST3410PublicKeyParameterSetSpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)

Example 2 with GOST3410PublicKeyParameterSetSpec

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

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

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

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

the class KeyFactorySpi method engineGetKeySpec.

protected KeySpec engineGetKeySpec(Key key, Class spec) throws InvalidKeySpecException {
    if (spec.isAssignableFrom(GOST3410PublicKeySpec.class) && key instanceof GOST3410PublicKey) {
        GOST3410PublicKey k = (GOST3410PublicKey) key;
        GOST3410PublicKeyParameterSetSpec parameters = k.getParameters().getPublicKeyParameters();
        return new GOST3410PublicKeySpec(k.getY(), parameters.getP(), parameters.getQ(), parameters.getA());
    } else if (spec.isAssignableFrom(GOST3410PrivateKeySpec.class) && key instanceof GOST3410PrivateKey) {
        GOST3410PrivateKey k = (GOST3410PrivateKey) key;
        GOST3410PublicKeyParameterSetSpec parameters = k.getParameters().getPublicKeyParameters();
        return new GOST3410PrivateKeySpec(k.getX(), parameters.getP(), parameters.getQ(), parameters.getA());
    }
    return super.engineGetKeySpec(key, spec);
}
Also used : GOST3410PrivateKeySpec(com.github.zhenwei.provider.jce.spec.GOST3410PrivateKeySpec) GOST3410PublicKey(com.github.zhenwei.provider.jce.interfaces.GOST3410PublicKey) GOST3410PublicKeySpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeySpec) GOST3410PrivateKey(com.github.zhenwei.provider.jce.interfaces.GOST3410PrivateKey) GOST3410PublicKeyParameterSetSpec(com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)

Aggregations

GOST3410PublicKeyParameterSetSpec (com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)7 GOST3410Parameters (com.github.zhenwei.core.crypto.params.GOST3410Parameters)4 GOST3410ParameterSpec (com.github.zhenwei.provider.jce.spec.GOST3410ParameterSpec)3 DEROctetString (com.github.zhenwei.core.asn1.DEROctetString)2 GOST3410PrivateKey (com.github.zhenwei.provider.jce.interfaces.GOST3410PrivateKey)2 GOST3410PublicKey (com.github.zhenwei.provider.jce.interfaces.GOST3410PublicKey)2 InvalidKeyException (java.security.InvalidKeyException)2 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)1 GOST3410ParametersGenerator (com.github.zhenwei.core.crypto.generators.GOST3410ParametersGenerator)1 GOST3410KeyGenerationParameters (com.github.zhenwei.core.crypto.params.GOST3410KeyGenerationParameters)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 GOST3410PrivateKeySpec (com.github.zhenwei.provider.jce.spec.GOST3410PrivateKeySpec)1 GOST3410PublicKeySpec (com.github.zhenwei.provider.jce.spec.GOST3410PublicKeySpec)1 AlgorithmParameters (java.security.AlgorithmParameters)1 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1