From 147f29a9ddbe119b8d32ef0522a3275250ea281c Mon Sep 17 00:00:00 2001 From: Hatter Jiang Date: Sun, 3 Sep 2023 23:22:16 +0800 Subject: [PATCH] feat: update readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index d03f516..d050914 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,21 @@ PENGING... + +BC test code: +```java +public static void encryptGcmNoPadding(String key, String data, String nonce, String associatedData) throws Exception { + Cipher cipher = Cipher.getInstance("SM4/GCM/NoPadding", BouncyCastleProvider.PROVIDER_NAME); + Key sm4Key = new SecretKeySpec(Bytes.fromHex(key).bytes(), "SM4"); + byte[] iv = Bytes.fromHex(nonce).bytes(); + GCMParameterSpec s = new GCMParameterSpec(128, iv); + cipher.init(Cipher.ENCRYPT_MODE, sm4Key, s); + if (associatedData != null && associatedData.length() > 0) { + cipher.updateAAD(Bytes.fromHex(associatedData).bytes()); + } + byte[] aa = cipher.doFinal(data.getBytes(StandardCharsets.UTF_8)); + System.out.println(Bytes.from(aa).asHex()); +} +``` + +