我们平常都使用jdk自带的加密包对数据进行加密,加密方式也都是使用的默认的,如果我们想选择别的加密方式,发现会报错,比如如下代码:
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8"), "AES"));
cipher.doFinal("QWEASDZS".getBytes("UTF-8"));
这时候我们就需要借助BouncyCastle了。
(1)在代码中通过maven引入BouncyCastle的包
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.56</version>
</dependency>
(2)在代码中手动添加provider:
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA".getBytes("UTF-8"), "AES"));
cipher.doFinal("QWEASDZS".getBytes("UTF-8"));
openssl smime -sign -signer cert.crt -inkey private.key -out file.xml.cms -in file.xml -outform PEM -nodetach
------------------------------------------------------------------------------------------------------------------
https://codingdict.com/questions/118103
https://blog.csdn.net/u011024652/article/details/53520728
https://codingdict.com/questions/111964
https://www.manongdao.com/article-1007555.html
https://www.javaroad.cn/questions/155262