List of usage examples for org.bouncycastle.crypto.params X25519PrivateKeyParameters X25519PrivateKeyParameters
public X25519PrivateKeyParameters(byte[] buf, int off)
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 a va2 s .com 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); } }