Example usage for org.bouncycastle.crypto.params Ed25519PublicKeyParameters Ed25519PublicKeyParameters

List of usage examples for org.bouncycastle.crypto.params Ed25519PublicKeyParameters Ed25519PublicKeyParameters

Introduction

In this page you can find the example usage for org.bouncycastle.crypto.params Ed25519PublicKeyParameters Ed25519PublicKeyParameters.

Prototype

public Ed25519PublicKeyParameters(byte[] buf, int off) 

Source Link

Usage

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 {//from  w  w 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);
    }

}