Skip to content

Commit

Permalink
Switch to language level 7, and switch Base64 decoder in AESUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
pokkst committed Mar 17, 2020
1 parent 9e6c90a commit 6e50aa1
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions core/src/main/java/org/bitcoinj/crypto/AESUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
import java.util.Base64;

import org.spongycastle.crypto.BufferedBlockCipher;
import org.spongycastle.crypto.CipherParameters;
Expand All @@ -21,6 +20,7 @@
import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher;
import org.spongycastle.crypto.params.KeyParameter;
import org.spongycastle.crypto.params.ParametersWithIV;
import org.spongycastle.util.encoders.Base64;

public class AESUtil {
public static final int PinPbkdf2Iterations = 5000;
Expand All @@ -36,8 +36,7 @@ private static byte[] copyOfRange(byte[] source, int from, int to) {
}

public static String decrypt(String ciphertext, CharSequenceX password, int iterations) {
boolean AESBlockSize = true;
byte[] cipherdata = Base64.getDecoder().decode(ciphertext.getBytes());
byte[] cipherdata = Base64.decode(ciphertext.getBytes());
byte[] iv = copyOfRange(cipherdata, 0, 16);
byte[] input = copyOfRange(cipherdata, 16, cipherdata.length);
PBEParametersGenerator generator = new PKCS5S2ParametersGenerator();
Expand Down Expand Up @@ -66,7 +65,6 @@ public static String decrypt(String ciphertext, CharSequenceX password, int iter
}

public static String encrypt(String cleartext, CharSequenceX password, int iterations) {
boolean AESBlockSize = true;
if (password == null) {
return null;
} else {
Expand All @@ -92,7 +90,7 @@ public static String encrypt(String cleartext, CharSequenceX password, int itera
byte[] ivAppended = new byte[len1 + len2];
System.arraycopy(iv, 0, ivAppended, 0, len1);
System.arraycopy(outBuf, 0, ivAppended, len1, len2);
byte[] raw = Base64.getEncoder().encode(ivAppended);
byte[] raw = Base64.encode(ivAppended);
String ret = new String(raw);
return ret;
}
Expand Down

0 comments on commit 6e50aa1

Please sign in to comment.