public class KeyCrypterScrypt extends Object implements KeyCrypter
This class encrypts and decrypts byte arrays and strings using scrypt as the key derivation function and AES for the encryption.
You can use this class to:
1) Using a user password, create an AES key that can encrypt and decrypt your private keys. To convert the password to the AES key, scrypt is used. This is an algorithm resistant to brute force attacks. You can use the ScryptParameters to tune how difficult you want this to be generation to be.
2) Using the AES Key generated above, you then can encrypt and decrypt any bytes using the AES symmetric cipher. Eight bytes of salt is used to prevent dictionary attacks.
Modifier and Type | Field and Description |
---|---|
static int |
BLOCK_LENGTH
The size of an AES block in bytes.
|
static int |
KEY_LENGTH
Key length in bytes.
|
static int |
SALT_LENGTH
The length of the salt used.
|
Constructor and Description |
---|
KeyCrypterScrypt()
Encryption/Decryption using default parameters and a random salt.
|
KeyCrypterScrypt(int iterations)
Encryption/Decryption using custom number of iterations parameters and a random salt.
|
KeyCrypterScrypt(Protos.ScryptParameters scryptParameters)
Encryption/ Decryption using specified Scrypt parameters.
|
Modifier and Type | Method and Description |
---|---|
byte[] |
decrypt(EncryptedData dataToDecrypt,
org.spongycastle.crypto.params.KeyParameter aesKey)
Decrypt bytes previously encrypted with this class.
|
org.spongycastle.crypto.params.KeyParameter |
deriveKey(CharSequence password)
Generate AES key.
|
EncryptedData |
encrypt(byte[] plainBytes,
org.spongycastle.crypto.params.KeyParameter aesKey)
Password based encryption using AES - CBC 256 bits.
|
boolean |
equals(Object o) |
Protos.ScryptParameters |
getScryptParameters() |
Protos.Wallet.EncryptionType |
getUnderstoodEncryptionType()
Return the EncryptionType enum value which denotes the type of encryption/ decryption that this KeyCrypter
can understand.
|
int |
hashCode() |
static byte[] |
randomSalt()
Returns SALT_LENGTH (8) bytes of random data
|
String |
toString() |
public static final int KEY_LENGTH
public static final int BLOCK_LENGTH
public static final int SALT_LENGTH
public KeyCrypterScrypt()
public KeyCrypterScrypt(int iterations)
iterations
- number of scrypt iterationspublic KeyCrypterScrypt(Protos.ScryptParameters scryptParameters)
scryptParameters
- ScryptParameters to useNullPointerException
- if the scryptParameters or any of its N, R or P is null.public static byte[] randomSalt()
public org.spongycastle.crypto.params.KeyParameter deriveKey(CharSequence password) throws KeyCrypterException
deriveKey
in interface KeyCrypter
password
- The password to use in key generationKeyCrypterException
public EncryptedData encrypt(byte[] plainBytes, org.spongycastle.crypto.params.KeyParameter aesKey) throws KeyCrypterException
encrypt
in interface KeyCrypter
KeyCrypterException
- if encryption was unsuccessfulpublic byte[] decrypt(EncryptedData dataToDecrypt, org.spongycastle.crypto.params.KeyParameter aesKey) throws KeyCrypterException
decrypt
in interface KeyCrypter
dataToDecrypt
- The data to decryptaesKey
- The AES key to use for decryptionKeyCrypterException
- if bytes could not be decryptedpublic Protos.ScryptParameters getScryptParameters()
public Protos.Wallet.EncryptionType getUnderstoodEncryptionType()
getUnderstoodEncryptionType
in interface KeyCrypter
Copyright © 2016. All rights reserved.