我的代码是
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class apiKeyGenerate {
public static void main(String[] args) throws Exception {
// Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
byte[] input = "input".getBytes();
byte[] ivBytes = "1234567812345678".getBytes();
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
KeyGenerator generator = KeyGenerator.getInstance("AES", "BC");
generator.init(128);
Key encryptionKey = generator.generateKey();
System.out.println("key : " + new String(encryptionKey.getEncoded()));
}
}
在上面的代码中,火异常是:- java.security.NoSuchProviderException:即
Exception in thread "main" java.security.NoSuchProviderException: no such provider: BC
at sun.security.jca.GetInstance.getService(Unknown Source)
at javax.crypto.SunJCE_b.a(DashoA13*..)
at javax.crypto.KeyGenerator.getInstance(DashoA13*..)
at apiKeyGenerate.main(apiKeyGenerate.java:17)
我怎样才能做到这一点 ??提前致谢