From 09129b38a1837c41d527619cfca63c0d551f81d9 Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sat, 31 Aug 2024 17:34:13 +0800 Subject: [PATCH] feat: udpate __crypto/aes_ctr_test --- __crypto/aes_ctr_test/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 __crypto/aes_ctr_test/README.md diff --git a/__crypto/aes_ctr_test/README.md b/__crypto/aes_ctr_test/README.md new file mode 100644 index 0000000..2b2b9e5 --- /dev/null +++ b/__crypto/aes_ctr_test/README.md @@ -0,0 +1,23 @@ + +Test Java codes: +```java +public class AesCtrTest { + + public static void main(String[] args) throws Exception { + final byte[] key = new byte[]{ + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + }; + final byte[] iv = new byte[]{ + 1, 2, 3, 4, 5, 6, 7, 8, 0, 0, 0, 0, 0, 0, 0, 0 + }; + final SecretKeySpec keySpec = new SecretKeySpec(key, "AES"); + + final Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding"); + cipher.init(Cipher.ENCRYPT_MODE, keySpec, new IvParameterSpec(iv)); + System.out.println(Bytes.from(cipher.doFinal("hello world".getBytes())).asHex()); + System.out.println(Bytes.from(cipher.doFinal( + "hello world.hello world.hello world.hello world.hello world.hello world.".getBytes())).asHex()); + } +} + +```