Example usage for org.bouncycastle.pqc.jcajce.provider.sphincs Sphincs256KeyFactorySpi engineGeneratePrivate

List of usage examples for org.bouncycastle.pqc.jcajce.provider.sphincs Sphincs256KeyFactorySpi engineGeneratePrivate

Introduction

In this page you can find the example usage for org.bouncycastle.pqc.jcajce.provider.sphincs Sphincs256KeyFactorySpi engineGeneratePrivate.

Prototype

public PrivateKey engineGeneratePrivate(KeySpec keySpec) throws InvalidKeySpecException 

Source Link

Usage

From source file:com.distrimind.util.crypto.ASymmetricEncryptionType.java

License:Open Source License

static PrivateKey decodeNativePrivateKey(byte[] encodedKey, String algorithm, String algorithmType, boolean xdh)
        throws NoSuchAlgorithmException, InvalidKeySpecException {

    try {/*ww w  . j ava2s. c om*/
        if (algorithmType.contains("SPHINCS")) {
            Sphincs256KeyFactorySpi kf = new Sphincs256KeyFactorySpi();
            return kf.engineGeneratePrivate(new PKCS8EncodedKeySpec(encodedKey));
        } else if (algorithmType.contains("CURVE_25519")) {
            ECPrivateKeySpec ks = deserializePrivateKey(encodedKey, false);
            return KeyFactory.getInstance(algorithm).generatePrivate(ks);

        } else if (algorithmType.contains(ASymmetricAuthenticatedSignatureType.BC_Ed25519.getCurveName())) {
            if (xdh) {
                X25519PrivateKeyParameters pk = new X25519PrivateKeyParameters(encodedKey, 0);
                return constructorBCXDHPrivateKey.newInstance(pk);

            } else {
                Ed25519PrivateKeyParameters pk = new Ed25519PrivateKeyParameters(encodedKey, 0);
                return constructorBCEdDSAPrivateKey.newInstance(pk);
            }
        } else if (algorithmType.contains(ASymmetricAuthenticatedSignatureType.BC_Ed448.getCurveName())) {
            if (xdh) {
                X448PrivateKeyParameters pk = new X448PrivateKeyParameters(encodedKey, 0);
                return constructorBCXDHPrivateKey.newInstance(pk);

            } else {
                Ed448PrivateKeyParameters pk = new Ed448PrivateKeyParameters(encodedKey, 0);
                return constructorBCEdDSAPrivateKey.newInstance(pk);
            }
        }

        else {

            PKCS8EncodedKeySpec pkcsKeySpec = new PKCS8EncodedKeySpec(encodedKey);
            KeyFactory kf = KeyFactory.getInstance(algorithm);
            return kf.generatePrivate(pkcsKeySpec);
        }
    } catch (InvalidKeySpecException | InstantiationException | IllegalAccessException
            | InvocationTargetException e) {
        throw new InvalidKeySpecException(e);
    }
}