From 98a69960d67e4ee7bdd5c3ed88c2f8b7be20b52c Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Fri, 22 Jul 2016 16:52:01 +0200 Subject: [PATCH] fix io (IDEA-158917) --- .../proxy/PropertiesEncryptionSupport.java | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java b/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java index 302fffedc8cd..0fc4e8478e6d 100644 --- a/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java +++ b/platform/platform-api/src/com/intellij/util/proxy/PropertiesEncryptionSupport.java @@ -64,11 +64,11 @@ public class PropertiesEncryptionSupport { FileUtil.writeToFile(file, encrypt(out.toByteArray())); } - private byte[] encrypt(byte[] bytes) throws Exception { + public byte[] encrypt(byte[] bytes) throws Exception { return encrypt(bytes, myKey); } - private byte[] decrypt(byte[] bytes) throws Exception { + public byte[] decrypt(byte[] bytes) throws Exception { return decrypt(bytes, myKey); } @@ -92,10 +92,10 @@ public class PropertiesEncryptionSupport { } private static byte[] decrypt(byte[] data, Key key) throws Exception { - int bodyLength = data[0] & 0xFF; - bodyLength = (bodyLength << 8) + data[1] & 0xFF; - bodyLength = (bodyLength << 8) + data[2] & 0xFF; - bodyLength = (bodyLength << 8) + data[3] & 0xFF; + final int bodyLength = ((data[0] & 0xFF) << 24) | + ((data[1] & 0xFF) << 16) | + ((data[2] & 0xFF) << 8) | + ((data[3] & 0xFF) ); final int ivlength = data.length - 4 - bodyLength; @@ -104,4 +104,22 @@ public class PropertiesEncryptionSupport { return ciph.doFinal(data, 4 + ivlength, bodyLength); } + //public static void main(String[] args) throws Exception { + // final PropertiesEncryptionSupport support = new PropertiesEncryptionSupport(); + // final Charset charset = Charset.forName("utf-8"); + // final SecureRandom rnd = new SecureRandom(); + // for (int idx = 0; idx < 90; idx++) { + // final String message = new BigInteger(10 * 1024, rnd).toString(); + // final byte[] encrypted = support.encrypt(message.getBytes(charset)); + // String decrypted = new String(support.decrypt(encrypted), charset); + // if (message.equals(decrypted)) { + // System.out.println("Test " + idx + " ok"); + // } + // else { + // System.out.println("Test " + idx + " FAILED"); + // } + // } + //} + + }