求blowfish-ECB模式加密源码!

weixin_48869435 2020-10-14 10:29:00
公司要求对接其他系统,那边负责人调试blowfish-ECB成功,但是我在网上看的源代码加解密都是CBC模式,有没有大佬有ECB的源代码?
...全文
2866 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
tianfang 2020-10-15
  • 打赏
  • 举报
回复
https://www.dbmng.com/art-2170.html Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); 文档从: https://docs.oracle.com/javase/8/docs/api/javax/crypto/Cipher.html#getInstance-java.lang.String- 继续找到: https://docs.oracle.com/javase/8/docs/technotes/guides/security/StandardNames.html#Cipher Blowfish/ECB/PKCS5Padding 分别从Cipher Algorithm Names, Cipher Algorithm Modes,Cipher Algorithm Padding 中查找
h2plus0 2020-10-15
  • 打赏
  • 举报
回复
下面的代码是blowfish ECB模式加解密,注意假定使用的是 PKCS5Padding, 两方需要保持一致 // https://stackoverflow.com/questions/22733157/java-blowfish-encryption-decryption-bad-padding-exception

	public static void main(String[] args) throws Exception {
		 String mykey="key1";
		 
		 String text = "this is the secret msg";
		 SecretKeySpec key = new SecretKeySpec(mykey.getBytes("UTF-8"), "Blowfish");
		 
		 Cipher cipher = Cipher.getInstance("Blowfish/ECB/PKCS5Padding"); //NoPadding");
		 
		 if ( cipher == null || key == null) {
			 throw new Exception("Invalid key or cypher");
		 }
		 
		 // encrypt
		 cipher.init(Cipher.ENCRYPT_MODE, key);
		 byte[] encrypted = cipher.doFinal(text.getBytes("UTF-8"));

		 // decrypt	 
		 cipher.init(Cipher.DECRYPT_MODE,  key);
		 byte[] plainBytes = cipher.doFinal(encrypted);
		 
		 String text2 = new String(plainBytes, "UTF-8");
		 System.out.println(text2);
	}
叶墨墨 2020-10-15
  • 打赏
  • 举报
回复
好的,我试一下,谢谢
Wechat:IT201105 2020-10-14
  • 打赏
  • 举报
回复
https://www.yuque.com/docs/share/a38feb12-ac05-41bb-9f88-b9eaa581d2fc?# 《2020最新it资源目录,,持续更新》

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧