Search in sources :

Example 1 with GOST3410PrivateKey

use of com.github.zhenwei.provider.jce.interfaces.GOST3410PrivateKey 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)

Example 2 with GOST3410PrivateKey

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

GOST3410PrivateKey (com.github.zhenwei.provider.jce.interfaces.GOST3410PrivateKey)2 GOST3410PublicKeyParameterSetSpec (com.github.zhenwei.provider.jce.spec.GOST3410PublicKeyParameterSetSpec)2 GOST3410Parameters (com.github.zhenwei.core.crypto.params.GOST3410Parameters)1 GOST3410PrivateKeyParameters (com.github.zhenwei.core.crypto.params.GOST3410PrivateKeyParameters)1 GOST3410PublicKey (com.github.zhenwei.provider.jce.interfaces.GOST3410PublicKey)1 GOST3410PrivateKeySpec (com.github.zhenwei.provider.jce.spec.GOST3410PrivateKeySpec)1 GOST3410PublicKeySpec (com.github.zhenwei.provider.jce.spec.GOST3410PublicKeySpec)1 InvalidKeyException (java.security.InvalidKeyException)1