aboutsummaryrefslogtreecommitdiff
path: root/other/java/client/src/test
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-03-14 00:27:57 -0700
committerChris Lu <chris.lu@gmail.com>2020-03-14 00:27:57 -0700
commitde1ba85346bd2af41ebb98f152bb769e2b630139 (patch)
treef3d65d148e69e1b84ef17a953f1f0fa14286aae1 /other/java/client/src/test
parente2e691d9c23d2b18b032f4d464ca0756c134ed87 (diff)
downloadseaweedfs-de1ba85346bd2af41ebb98f152bb769e2b630139.tar.xz
seaweedfs-de1ba85346bd2af41ebb98f152bb769e2b630139.zip
HDFS support encrypted data storage
Diffstat (limited to 'other/java/client/src/test')
-rw-r--r--other/java/client/src/test/java/seaweedfs/client/SeaweedCipherTest.java42
1 files changed, 42 insertions, 0 deletions
diff --git a/other/java/client/src/test/java/seaweedfs/client/SeaweedCipherTest.java b/other/java/client/src/test/java/seaweedfs/client/SeaweedCipherTest.java
new file mode 100644
index 000000000..7b5e53e19
--- /dev/null
+++ b/other/java/client/src/test/java/seaweedfs/client/SeaweedCipherTest.java
@@ -0,0 +1,42 @@
+package seaweedfs.client;
+
+import org.junit.Test;
+
+import java.util.Base64;
+
+import static seaweedfs.client.SeaweedCipher.decrypt;
+import static seaweedfs.client.SeaweedCipher.encrypt;
+
+public class SeaweedCipherTest {
+
+ @Test
+ public void testSameAsGoImplemnetation() throws Exception {
+ byte[] secretKey = "256-bit key for AES 256 GCM encr".getBytes();
+
+ String plainText = "Now we need to generate a 256-bit key for AES 256 GCM";
+
+ System.out.println("Original Text : " + plainText);
+
+ byte[] cipherText = encrypt(plainText.getBytes(), secretKey);
+ System.out.println("Encrypted Text : " + Base64.getEncoder().encodeToString(cipherText));
+
+ byte[] decryptedText = decrypt(cipherText, secretKey);
+ System.out.println("DeCrypted Text : " + new String(decryptedText));
+ }
+
+ @Test
+ public void testEncryptDecrypt() throws Exception {
+ byte[] secretKey = SeaweedCipher.genCipherKey();
+
+ String plainText = "Now we need to generate a 256-bit key for AES 256 GCM";
+
+ System.out.println("Original Text : " + plainText);
+
+ byte[] cipherText = encrypt(plainText.getBytes(), secretKey);
+ System.out.println("Encrypted Text : " + Base64.getEncoder().encodeToString(cipherText));
+
+ byte[] decryptedText = decrypt(cipherText, secretKey);
+ System.out.println("DeCrypted Text : " + new String(decryptedText));
+ }
+
+}