Skip to content
This repository was archived by the owner on Apr 19, 2022. It is now read-only.

Commit d11cb9f

Browse files
committed
Print out Cipher max key length.
1 parent 56ff5d1 commit d11cb9f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

java-api/src/main/java/com/xapo/micro/payment/encrypt/MCrypt.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public MCrypt()
3636

3737
public String encrypt(String secretKey, String text) throws Exception
3838
{
39-
SecretKeySpec keyspec = new SecretKeySpec(secretKey.getBytes(), "AES");
39+
SecretKeySpec keyspec = new SecretKeySpec(secretKey.getBytes("UTF-8"), "AES");
4040

4141
if(text == null || text.length() == 0)
4242
throw new Exception("Empty string");
@@ -46,7 +46,7 @@ public String encrypt(String secretKey, String text) throws Exception
4646
try {
4747
cipher.init(Cipher.ENCRYPT_MODE, keyspec);
4848

49-
encrypted = cipher.doFinal(padString(text).getBytes());
49+
encrypted = cipher.doFinal(padString(text).getBytes("UTF-8"));
5050
} catch (Exception e)
5151
{
5252
e.printStackTrace();

java-api/src/test/java/com/xapo/micro/payment/encrypt/AESencryptTest.java

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.junit.Test;
88

99
import java.security.Security;
10+
import javax.crypto.Cipher;
1011

1112
public class AESencryptTest {
1213

@@ -45,6 +46,10 @@ public void testEncryptJson() throws Exception {
4546
public void testEncryptHello() throws Exception {
4647
String textToEncrypt = "hello from aes encryption!";
4748

49+
System.out.println("********************************");
50+
System.out.println(Cipher.getMaxAllowedKeyLength("AES"));
51+
System.out.println("********************************");
52+
4853
String encryptedText = aesEncrypt.encrypt(APP_SECRET, textToEncrypt);
4954
String expected = "Jr/PhEWZBiqW/iMnoObyPm5M4azsUYLwLxk50Wi9eoo=";
5055
assertEquals("encrypted text must be equals ", expected, encryptedText);

0 commit comments

Comments
 (0)