これは、BlowFish 暗号化/復号化で直面している問題です。
以下のコードは、BlowFish 暗号化/復号化のテストに使用されます。
// Code below omits comments for Brevity
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.math.BigInteger;
public class JBoss {
public static void main(String[] args) throws Exception {
if ((args.length != 2)
|| !(args[0].equals("-e") | args[0].equals("-d"))) {
System.out
.println("Usage:\n\tjava JBoss <-e|-d> <encrypted_password>");
return;
}
String mode = args[0];
byte[] kbytes = "jaas is the way".getBytes();
SecretKeySpec key = new SecretKeySpec(kbytes, "Blowfish");
Cipher cipher = Cipher.getInstance("Blowfish");
String out = null;
if (mode.equals("-e")) {
String secret = args[1];
cipher.init(Cipher.ENCRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.getBytes());
out = new BigInteger(encoding).toString(16);
} else {
BigInteger secret = new BigInteger(args[1], 16);
cipher.init(Cipher.DECRYPT_MODE, key);
byte[] encoding = cipher.doFinal(secret.toByteArray());
out = new String(encoding);
}
System.out.println(out);
}
}
今、文字列を暗号化しようとすると
u7mzqw2
私は次のように値を取得します
-7ccb7ff0c2858a
解読しようとすると
-7ccb7ff0c2858a
以下のようなエラーが表示されます。
java JBoss -d -7ccb7ff0c2858a
Exception in thread "main" javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.SunJCE_f.b(DashoA13*..)
at com.sun.crypto.provider.BlowfishCipher.engineDoFinal(DashoA13*..)
at javax.crypto.Cipher.doFinal(DashoA13*..)
at JBoss.main(JBoss.java:41)
コード全体はこちら
以下のものが機能するため、私が間違っていなければ、7文字の長さの元の値または/ 8 = 0以外の暗号化された値とは何の関係もありません
Java JBoss -e qwerty
-40e961f375c2eee6
Java JBoss -d -40e961f375c2eee6
クォーター
私は何が欠けていますか??