mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-07 14:54:15 +00:00
KeyCrypterScrypt: Fix some minor code style issues.
This commit is contained in:
parent
53dc5c2e6a
commit
48cee2e668
@ -15,7 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.bitcoin.crypto;
|
package com.google.bitcoin.crypto;
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
import com.lambdaworks.crypto.SCrypt;
|
import com.lambdaworks.crypto.SCrypt;
|
||||||
import org.bitcoinj.wallet.Protos;
|
import org.bitcoinj.wallet.Protos;
|
||||||
@ -33,6 +32,8 @@ import org.spongycastle.crypto.params.ParametersWithIV;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>This class encrypts and decrypts byte arrays and strings using scrypt as the
|
* <p>This class encrypts and decrypts byte arrays and strings using scrypt as the
|
||||||
* key derivation function and AES for the encryption.</p>
|
* key derivation function and AES for the encryption.</p>
|
||||||
@ -67,10 +68,10 @@ public class KeyCrypterScrypt implements KeyCrypter, Serializable {
|
|||||||
*/
|
*/
|
||||||
public static final int SALT_LENGTH = 8;
|
public static final int SALT_LENGTH = 8;
|
||||||
|
|
||||||
transient private static SecureRandom secureRandom = new SecureRandom();
|
private static final transient SecureRandom secureRandom = new SecureRandom();
|
||||||
|
|
||||||
// Scrypt parameters.
|
// Scrypt parameters.
|
||||||
transient private ScryptParameters scryptParameters;
|
private final transient ScryptParameters scryptParameters;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Encryption/ Decryption using default parameters and a random salt
|
* Encryption/ Decryption using default parameters and a random salt
|
||||||
@ -89,7 +90,7 @@ public class KeyCrypterScrypt implements KeyCrypter, Serializable {
|
|||||||
* @throws NullPointerException if the scryptParameters or any of its N, R or P is null.
|
* @throws NullPointerException if the scryptParameters or any of its N, R or P is null.
|
||||||
*/
|
*/
|
||||||
public KeyCrypterScrypt(ScryptParameters scryptParameters) {
|
public KeyCrypterScrypt(ScryptParameters scryptParameters) {
|
||||||
this.scryptParameters = Preconditions.checkNotNull(scryptParameters);
|
this.scryptParameters = checkNotNull(scryptParameters);
|
||||||
// Check there is a non-empty salt.
|
// Check there is a non-empty salt.
|
||||||
// (Some early MultiBit wallets has a missing salt so it is not a hard fail).
|
// (Some early MultiBit wallets has a missing salt so it is not a hard fail).
|
||||||
if (scryptParameters.getSalt() == null
|
if (scryptParameters.getSalt() == null
|
||||||
@ -139,8 +140,8 @@ public class KeyCrypterScrypt implements KeyCrypter, Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public EncryptedPrivateKey encrypt(byte[] plainBytes, KeyParameter aesKey) throws KeyCrypterException {
|
public EncryptedPrivateKey encrypt(byte[] plainBytes, KeyParameter aesKey) throws KeyCrypterException {
|
||||||
Preconditions.checkNotNull(plainBytes);
|
checkNotNull(plainBytes);
|
||||||
Preconditions.checkNotNull(aesKey);
|
checkNotNull(aesKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Generate iv - each encryption call has a different iv.
|
// Generate iv - each encryption call has a different iv.
|
||||||
@ -173,8 +174,8 @@ public class KeyCrypterScrypt implements KeyCrypter, Serializable {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] decrypt(EncryptedPrivateKey privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
|
public byte[] decrypt(EncryptedPrivateKey privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
|
||||||
Preconditions.checkNotNull(privateKeyToDecode);
|
checkNotNull(privateKeyToDecode);
|
||||||
Preconditions.checkNotNull(aesKey);
|
checkNotNull(aesKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.getInitialisationVector());
|
ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.getInitialisationVector());
|
||||||
@ -204,8 +205,8 @@ public class KeyCrypterScrypt implements KeyCrypter, Serializable {
|
|||||||
*
|
*
|
||||||
* Note: a String.getBytes() is not used to avoid creating a String of the password in the JVM.
|
* Note: a String.getBytes() is not used to avoid creating a String of the password in the JVM.
|
||||||
*/
|
*/
|
||||||
private byte[] convertToByteArray(CharSequence charSequence) {
|
private static byte[] convertToByteArray(CharSequence charSequence) {
|
||||||
Preconditions.checkNotNull(charSequence);
|
checkNotNull(charSequence);
|
||||||
|
|
||||||
byte[] byteArray = new byte[charSequence.length() << 1];
|
byte[] byteArray = new byte[charSequence.length() << 1];
|
||||||
for(int i = 0; i < charSequence.length(); i++) {
|
for(int i = 0; i < charSequence.length(); i++) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user