Problème de gestion de cle RSA
bonjour je veux recuperer des clef prive et public de rsa à partir d'un tableau de byte, mais je n'y arrive pas
mes deux methodes :
Code:
1 2 3 4 5 6 7 8 9 10
| public static PrivateKey getPrivateKey(byte[] encKey) throws NoSuchAlgorithmException, NoSuchProviderException, InvalidKeySpecException{
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA","BC");
PrivateKey privKey = keyFactory.generatePrivate(pubKeySpec);
return (RSAPrivateKey)privKey;
} |
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| public static RSAPublicKey getPublicKey(byte[] encKey) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException
{
Security.addProvider(new BouncyCastleProvider());
X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
KeyFactory keyFactory = KeyFactory.getInstance("RSA","BC");
PublicKey pubKey = keyFactory.generatePublic(pubKeySpec);
return (RSAPublicKey) pubKey;
} |