我用 javafx 制作了一個應用程序,我可以編寫一些東西并將其保存到數據庫中。我的數據庫是sqlite。這是一個非常簡單的應用程序。雖然我已經在我的寫作應用程序中添加了登錄應用程序,但仍然可以通過任何軟件打開 sqlite。而不是加密sqlite db(我不知道,我發現做起來真的很困惑:))我決定在java中加密文本,稍后當我想閱讀它時,我會將它恢復正常并顯示它。我從這個鏈接學會了如何做到這一點,我將其更改為打印字符串而不是寫入文件,因此我的最終代碼如下所示:public static void main(String[] args) throws Exception { String textA = ""; String textB=""; byte[] thisismykey = "Hello How manyBytes are in@hts A".getBytes(); SecretKey secKey = new SecretKeySpec(thisismykey, "AES"); Cipher aesCipher = Cipher.getInstance("AES"); //turn your original text to byte byte[] myoriginaltexttobyte = "Your Plain Text Here".getBytes(); //activate the encrypt method aesCipher.init(Cipher.ENCRYPT_MODE, secKey); //encrypt the text and assign the encrypted text to a byte array byte[] bytecipheredoforgtext = aesCipher.doFinal(myoriginaltexttobyte); //change it to string with new string textA = new String(bytecipheredoforgtext); System.out.println(textA); //get the bytes of encrypted text and assign it to a byte array byte[] byteofencryptedtext = textA.getBytes(); //activate the decrypt mode of the cipher aesCipher.init(Cipher.DECRYPT_MODE, secKey); //decrypt the encrypted text and assign it to a byte array byte[] byteofencryptedbacktonormaltext = aesCipher.doFinal(byteofencryptedtext); //change it to string with new string textB = new String(byteofencryptedbacktonormaltext); System.out.println(textB);}現在加密和解密使用相同的方法,它可以完美運行,但我想將其更改為具有不同方法的類,以便我可以使用一種方法加密文本并使用另一種方法解密。但是當我將事物分開時,解密效果不佳。加密工作良好。我該怎么辦?
java密碼問題,當我想破譯它時
慕婉清6462132
2021-08-25 09:56:12