unreported exception InvalidKeySpecException.
Je doit faire un script java capable de générer une clé public et une clé privée rsa. J'ai réussi a récupérer du code sur le net, mais j'ai un soucis quand je le compile, voici mon code :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
import java.security.KeyFactory;
import java.security.spec.RSAPublicKeySpec;
import java.security.spec.RSAPrivateKeySpec;
import java.security.spec.InvalidKeySpecException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
public class RSA_encrypt {
static String getPublicKey (String name) throws InvalidKeySpecException, InvalidKeyException, NoSuchAlgorithmException {
KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
kpg.initialize(1024);
KeyPair kp = kpg.genKeyPair();
Key publicKey = kp.getPublic();
Key privateKey = kp.getPrivate();
KeyFactory fact = KeyFactory.getInstance("RSA");
RSAPublicKeySpec pub = fact.getKeySpec(kp.getPublic(),RSAPublicKeySpec.class);
RSAPrivateKeySpec priv = fact.getKeySpec(kp.getPrivate(),RSAPrivateKeySpec.class);
return name;
}
} |
Quand je compile ce code j' ai l'erreur suivante :
Code:
1 2 3
|
unreported exception java.security.spec.InvalidKeySpecException; must be caught or declared to be thrown
String rsaPublicKey=RSA_encrypt.getPublicKey("public_rsa.key"); |
Je ne comprend pas pourquoi car je fait bien l'import de import java.security.spec.InvalidKeySpecException;
et que je recupere bien l'erreur d'après moi... ??
Du coup je ne comprend pas ce qui fonctionne pas...
une idée ?