<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                1. AES算法簡介 AES加密過程涉及到4種操作:字節替代(SubBytes)、行移位(ShiftRows)、列混淆(MixColumns)和輪密鑰加(AddRoundKey)。解密過程分別為對應的逆操作。由于每一步操作都是可逆的,按照相反的順序進行解密即可恢復明文。加解密中每輪的密鑰分別由初始密鑰擴展得到。算法中16(byte)字節的明文、密文和輪密鑰都以一個4x4的矩陣表示。 AES的密碼必須是16byte。 參考博客:http://www.cnblogs.com/OneFri/p/5924605.html ![](https://box.kancloud.cn/683db905338afdafe92a717fd18f22df_280x280.jpg) 2. AES算法實現 AES的java實現比較簡單,只需要把密碼設置為16byte,然后將DES算法實現的java代碼中,將DES修改為AES即可。 ~~~ 1. package com; 2. 3. import java.io.UnsupportedEncodingException; 4. import java.security.InvalidKeyException; 5. import java.security.Key; 6. import java.security.NoSuchAlgorithmException; 7. 8. import javax.crypto.BadPaddingException; 9. import javax.crypto.Cipher; 10. import javax.crypto.IllegalBlockSizeException; 11. import javax.crypto.NoSuchPaddingException; 12. import javax.crypto.spec.SecretKeySpec; 13. 14. public class AESTest { 15. private static String psw = "1234656789765432"; 16. public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, 17. NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, 18. UnsupportedEncodingException { 19. String str = "你好,黑馬!"; 20. String encrypte = encrypte(str, psw); System.out.println("加密后:"+encrypte); 22. String decrypte = decrypte(encrypte, psw); 23. System.out.println("解密后:"+decrypte); 24. } 25. 26. private static String encrypte(String original,String psw) throws NoSuchAlgorithmException, 27. NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException{ 28. 29. Cipher cipher = Cipher.getInstance("AES"); 30. Key key = getAESKey(psw); 31. cipher.init(Cipher.ENCRYPT_MODE, key); 32. byte[] doFinal = cipher.doFinal(original.getBytes()); 33. return Base64.encode(doFinal); 34. } 35. 36. private static Key getAESKey(String psw) { 37. byte[] buffer = new byte[16]; 38. byte[] bytes = psw.getBytes(); 39. for(int i=0;i<buffer.length&&i<bytes.length;i++){ 40. buffer[i] = bytes[i]; 41. } 42. return new SecretKeySpec(buffer, "AES"); 43. } 44. 45. private static String decrypte(String original,String psw) throws NoSuchAlgorithmException, 46. NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException, 47. UnsupportedEncodingException{ 48. Cipher cipher = Cipher.getInstance("AES"); 49. Key aesKey = getAESKey(psw); 50. cipher.init(Cipher.DECRYPT_MODE, aesKey); 51. byte[] doFinal = cipher.doFinal(Base64.decode(original)); 52. return new String(doFinal); 53. } 54. } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看