File tree Expand file tree Collapse file tree
jpos/src/main/java/org/jpos Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525import javax .crypto .spec .GCMParameterSpec ;
2626import javax .crypto .spec .SecretKeySpec ;
2727import java .nio .ByteBuffer ;
28+ import java .nio .charset .StandardCharsets ;
2829import java .security .SecureRandom ;
2930import java .util .Base64 ;
3031
@@ -82,7 +83,7 @@ public String get(String config) {
8283 cipher .init (Cipher .DECRYPT_MODE , keySpec , gcmParameterSpec );
8384 byte [] plaintext = cipher .doFinal (ciphertext );
8485
85- return new String (plaintext );
86+ return new String (plaintext , StandardCharsets . UTF_8 );
8687 } catch (Exception e ) {
8788 throw new RuntimeException ("Failed to decrypt value" , e );
8889 }
@@ -108,7 +109,7 @@ public static String encrypt(String value) {
108109 Cipher cipher = Cipher .getInstance (TRANSFORMATION );
109110 GCMParameterSpec gcmParameterSpec = new GCMParameterSpec (TAG_LENGTH_BITS , iv );
110111 cipher .init (Cipher .ENCRYPT_MODE , keySpec , gcmParameterSpec );
111- byte [] ciphertext = cipher .doFinal (value .getBytes ());
112+ byte [] ciphertext = cipher .doFinal (value .getBytes (StandardCharsets . UTF_8 ));
112113
113114 // Combine IV and ciphertext
114115 ByteBuffer buf = ByteBuffer .allocate (iv .length + ciphertext .length );
Original file line number Diff line number Diff line change 2525import javax .crypto .spec .GCMParameterSpec ;
2626import javax .crypto .spec .SecretKeySpec ;
2727import java .nio .ByteBuffer ;
28+ import java .nio .charset .StandardCharsets ;
2829import java .security .SecureRandom ;
2930import java .util .Base64 ;
3031
@@ -70,7 +71,7 @@ public String encrypt(String value) {
7071 Cipher cipher = Cipher .getInstance (TRANSFORMATION );
7172 GCMParameterSpec gcmParameterSpec = new GCMParameterSpec (TAG_LENGTH_BITS , iv );
7273 cipher .init (Cipher .ENCRYPT_MODE , keySpec , gcmParameterSpec );
73- byte [] ciphertext = cipher .doFinal (value .getBytes ());
74+ byte [] ciphertext = cipher .doFinal (value .getBytes (StandardCharsets . UTF_8 ));
7475
7576 // Combine IV and ciphertext
7677 ByteBuffer buf = ByteBuffer .allocate (iv .length + ciphertext .length );
You can’t perform that action at this time.
0 commit comments