考慮下面的例子:加密數據與DES - JAVA
String f="A000000000000000";
FileInputStream fis = new FileInputStream("C:\\Users\\original.txt");
byte[] bytes = DatatypeConverter.parseHexBinary(f);
SecretKey key = new SecretKeySpec(bytes, 0, bytes.length, "DES");
String strDataToEncrypt = new String();
String strCipherText = new String();
String strDecryptedText = new String();
try{
Cipher desCipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
desCipher.init(Cipher.ENCRYPT_MODE,key);
//read from file and transform to String
try{
builder = new StringBuilder();
int ch;
while((ch = fis.read()) != -1){
builder.append((char)ch);
}
}catch (IOException e){
}
byte[] byteDataToEncrypt = builder.toString().getBytes();
byte[] byteCipherText = desCipher.doFinal(byteDataToEncrypt);
strCipherText = new BASE64Encoder().encode(byteCipherText);
System.out.println(strCipherText);
加密的數據不同的是,每次我用相同的密鑰值編譯我,我嘗試了不同的編碼和加密數據總是相同的,那是什麼這裏錯了嗎?
除此之外,此代碼未定義'fis'。意思是這段代碼不會編譯,意味着沒有人可以重現和調查問題,這意味着您將得到的答案要少得多。 – delnan
它的一部分代碼,ofc'fis'被定義。但這裏沒有提到,概率是用加密 – Zame