这是我正在做的事情,看起来有点笨拙,但任何帮助都对这个问题表示赞赏.我得到了一个BadPaddingException.阅读几乎所有相关主题,但没有找到合适的解决方案.我是加密解密编程的新手,需要在我的一个Java应用程序中实现它.
谢谢..这是代码看起来如何....
public static void main(String[] args) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
// TODO Auto-generated method stub
String FileName="encryptedtext.txt";
String FileName2="decryptedtext.txt";
String pad="0";
KeyGenerator KeyGen=KeyGenerator.getInstance("AES");
KeyGen.init(128);
SecretKey SecKey=KeyGen.generateKey();
Cipher AesCipher=Cipher.getInstance("AES");
AesCipher.init(Cipher.ENCRYPT_MODE,SecKey);
byte[] byteText="My name is yogesh".getBytes();
byte[] byteCipherText=AesCipher.doFinal(byteText);
String cipherText = null;
try {
FileWriter fw=new FileWriter(FileName);
BufferedWriter bw=new BufferedWriter(fw);
bw.write(byteCipherText.toString());
bw.close();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
FileReader fr=new FileReader(FileName);
BufferedReader br=new BufferedReader(fr);
cipherText=br.readLine();
br.close();
} catch (FileNotFoundException …Run Code Online (Sandbox Code Playgroud)