相关疑难解决方法(0)

使用Java进行AES加密和解密

这是我正在做的事情,看起来有点笨拙,但任何帮助都对这个问题表示赞赏.我得到了一个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)

java encryption cryptography aes

8
推荐指数
2
解决办法
6万
查看次数

标签 统计

aes ×1

cryptography ×1

encryption ×1

java ×1