List of usage examples for org.bouncycastle.crypto.params Ed448PublicKeyParameters Ed448PublicKeyParameters
public Ed448PublicKeyParameters(byte[] buf, int off)
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 {/* w w w. j a va 2 s. co m*/ //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); } }