Skip to content

Commit dea5554

Browse files
committed
Added encoding information
1 parent 875d75b commit dea5554

File tree

4 files changed

+7
-5
lines changed
  • crypto-java/src/main/java/de/dominikschadow/javasecurity
  • crypto-shiro/src/main/java/de/dominikschadow/javasecurity/symmetric
  • security-header/src/main/java/de/dominikschadow/javasecurity/header/servlets

4 files changed

+7
-5
lines changed

crypto-java/src/main/java/de/dominikschadow/javasecurity/asymmetric/RSA.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929
import java.io.InputStream;
3030
import java.io.UnsupportedEncodingException;
31+
import java.nio.charset.Charset;
3132
import java.security.*;
3233
import java.security.cert.CertificateException;
3334

@@ -121,6 +122,6 @@ private static byte[] decrypt(PrivateKey privateKey, byte[] ciphertext) throws N
121122
private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
122123
log.info("initial text: {}", initialText);
123124
log.info("cipher text: {}", BaseEncoding.base16().encode(ciphertext));
124-
log.info("plain text: {}", new String(plaintext));
125+
log.info("plain text: {}", new String(plaintext, Charset.forName("UTF-8")));
125126
}
126127
}

crypto-java/src/main/java/de/dominikschadow/javasecurity/symmetric/AES.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.io.IOException;
3131
import java.io.InputStream;
3232
import java.io.UnsupportedEncodingException;
33+
import java.nio.charset.Charset;
3334
import java.security.*;
3435
import java.security.cert.CertificateException;
3536

@@ -115,6 +116,6 @@ private byte[] decrypt(SecretKeySpec secretKeySpec, byte[] ciphertext) throws
115116
private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
116117
log.info("initial text: {}", initialText);
117118
log.info("cipher text: {}", BaseEncoding.base16().encode(ciphertext));
118-
log.info("plain text: {}", new String(plaintext));
119+
log.info("plain text: {}", new String(plaintext, Charset.forName("UTF-8")));
119120
}
120121
}

crypto-shiro/src/main/java/de/dominikschadow/javasecurity/symmetric/AES.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ private static Key loadKey(KeyStore ks, String keyAlias, char[] keyPassword) thr
8282
/**
8383
* Encrypts the given text using all Shiro defaults: 128 bit size, CBC mode, PKCS5 padding scheme.
8484
*
85-
* @param key The key to use
85+
* @param key The key to use
8686
* @param initialText The text to encrypt
8787
* @return The encrypted text
8888
*/
@@ -102,7 +102,6 @@ private static byte[] decrypt(Key key, byte[] ciphertext) {
102102

103103
private static void printReadableMessages(String initialText, byte[] ciphertext, byte[] plaintext) {
104104
log.info("initialText: {}", initialText);
105-
log.info("cipherText as byte[]: {}", new String(ciphertext));
106105
log.info("cipherText as HEX: {}", Hex.encodeToString(ciphertext));
107106
log.info("plaintext: {}", CodecSupport.toString(plaintext));
108107
}

security-header/src/main/java/de/dominikschadow/javasecurity/header/servlets/CSPReporting.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.io.BufferedReader;
3030
import java.io.IOException;
3131
import java.io.InputStreamReader;
32+
import java.nio.charset.Charset;
3233

3334
/**
3435
* Simple CSP-Reporting servlet to receive and print out any JSON style CSP report with violations.
@@ -42,7 +43,7 @@ public class CSPReporting extends HttpServlet {
4243

4344
@Override
4445
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException {
45-
try (BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()))) {
46+
try (BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream(), Charset.forName("UTF-8")))) {
4647
StringBuilder responseBuilder = new StringBuilder();
4748

4849
String inputStr;

0 commit comments

Comments
 (0)