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

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

Introduction

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

Prototype

Sphincs256KeyFactorySpi

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 {/*from   w  w  w  .  j  av a 2 s  . c o  m*/
        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);
    }
}

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

License:Open Source License

static PublicKey decodeNativePublicKey(byte[] encodedKey, String algorithm, String algorithmType,
        @SuppressWarnings("unused") String curveName, boolean xdh)
        throws NoSuchAlgorithmException, InvalidKeySpecException {
    try {// ww w  . j a  v a 2  s .c  om
        //byte[][] parts = Bits.separateEncodingsWithShortSizedTabs(encodedKey);

        if (algorithmType.contains("SPHINCS")) {
            Sphincs256KeyFactorySpi kf = new Sphincs256KeyFactorySpi();
            return kf.engineGeneratePublic(new X509EncodedKeySpec(encodedKey));
        } else if (algorithmType.contains("CURVE_25519")) {

            org.bouncycastle.jce.spec.ECPublicKeySpec ks = deserializePublicKey(encodedKey, false);
            return KeyFactory.getInstance(algorithm).generatePublic(ks);
        } else if (algorithmType.contains(ASymmetricAuthenticatedSignatureType.BC_Ed25519.getCurveName())) {
            if (xdh) {
                X25519PublicKeyParameters pk = new X25519PublicKeyParameters(encodedKey, 0);
                return constructorBCXDHPublicKey.newInstance(pk);
            } else {
                Ed25519PublicKeyParameters pk = new Ed25519PublicKeyParameters(encodedKey, 0);
                return constructorBCEdDSAPublicKey.newInstance(pk);
            }
        } else if (algorithmType.contains(ASymmetricAuthenticatedSignatureType.BC_Ed448.getCurveName())) {
            if (xdh) {
                X448PublicKeyParameters pk = new X448PublicKeyParameters(encodedKey, 0);
                return constructorBCXDHPublicKey.newInstance(pk);
            } else {
                Ed448PublicKeyParameters pk = new Ed448PublicKeyParameters(encodedKey, 0);
                return constructorBCEdDSAPublicKey.newInstance(pk);
            }
        }
        /*else if (algorithm.equalsIgnoreCase("ECDSA") && curveName!=null)
           {
        return getPubKeyFromCurve(encodedKey, curveName);
                
           }*/
        X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encodedKey);
        KeyFactory kf = KeyFactory.getInstance(algorithm);
        return kf.generatePublic(pubKeySpec);
    } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
        throw new InvalidKeySpecException(e);
    }

}