【发布时间】:2015-07-18 04:19:31
【问题描述】:
当我尝试使用 EC 公钥加密字节数组时出现以下异常:
java.security.InvalidKeyException:没有安装的提供程序支持这个 钥匙: sun.security.ec.ECPublicKeyImpl
当我调用Cipher.init() 时会产生此异常。以下几行显示了我在程序中所做的:
ECPublicKey publicKey ;
ECPrivateKey privateKey;
//Generating key paire (public and private keys)
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("EC", "SunEC");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG", "SUN");
keyGen.initialize(571, random);
KeyPair pair = keyGen.generateKeyPair();
privateKey = (ECPrivateKey) pair.getPrivate();
publicKey = (ECPublicKey) pair.getPublic();
// get an AES cipher object with CTR encription mode
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
// encrypt the sharedSecret using the public key
cipher.init(Cipher.ENCRYPT_MODE, publicKey);**
byte[] result = cipher.doFinal(data);
我必须添加一个提供程序来支持这个公钥吗?
【问题讨论】:
标签: java encryption public-key-encryption pki key-generator