公司要求對接其他系統,那邊負責人除錯blowfish-ECB成功,但是我在網上看的源代碼加解密都是CBC模式,有沒有大佬有ECB的源代碼?
uj5u.com熱心網友回復:
https://www.yuque.com/docs/share/a38feb12-ac05-41bb-9f88-b9eaa581d2fc?# 《2020最新it資源目錄,,持續更新》uj5u.com熱心網友回復:
下面的代碼是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);
}
uj5u.com熱心網友回復:
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 中查找
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/172311.html
標籤:Java SE
上一篇:webService 輸入服務地址加?wsdl訪問不到wsdl檔案
下一篇:jvm:位元組碼執行流程
