mirror of
https://github.com/Qortal/altcoinj.git
synced 2025-02-13 02:35:52 +00:00
KeyCrypterScrypt[Test]: more var/param name fixes
This commit is contained in:
parent
953cc311e3
commit
93fc0049f1
@ -198,24 +198,24 @@ public class KeyCrypterScrypt implements KeyCrypter, Serializable {
|
|||||||
/**
|
/**
|
||||||
* Decrypt bytes previously encrypted with this class.
|
* Decrypt bytes previously encrypted with this class.
|
||||||
*
|
*
|
||||||
* @param privateKeyToDecode The private key to decrypt
|
* @param dataToDecrypt The data to decrypt
|
||||||
* @param aesKey The AES key to use for decryption
|
* @param aesKey The AES key to use for decryption
|
||||||
* @return The decrypted bytes
|
* @return The decrypted bytes
|
||||||
* @throws KeyCrypterException if bytes could not be decoded to a valid key
|
* @throws KeyCrypterException if bytes could not be decrypted
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public byte[] decrypt(EncryptedData privateKeyToDecode, KeyParameter aesKey) throws KeyCrypterException {
|
public byte[] decrypt(EncryptedData dataToDecrypt, KeyParameter aesKey) throws KeyCrypterException {
|
||||||
checkNotNull(privateKeyToDecode);
|
checkNotNull(dataToDecrypt);
|
||||||
checkNotNull(aesKey);
|
checkNotNull(aesKey);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), privateKeyToDecode.initialisationVector);
|
ParametersWithIV keyWithIv = new ParametersWithIV(new KeyParameter(aesKey.getKey()), dataToDecrypt.initialisationVector);
|
||||||
|
|
||||||
// Decrypt the message.
|
// Decrypt the message.
|
||||||
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
|
BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine()));
|
||||||
cipher.init(false, keyWithIv);
|
cipher.init(false, keyWithIv);
|
||||||
|
|
||||||
byte[] cipherBytes = privateKeyToDecode.encryptedBytes;
|
byte[] cipherBytes = dataToDecrypt.encryptedBytes;
|
||||||
byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
|
byte[] decryptedBytes = new byte[cipher.getOutputSize(cipherBytes.length)];
|
||||||
final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
|
final int length1 = cipher.processBytes(cipherBytes, 0, cipherBytes.length, decryptedBytes, 0);
|
||||||
final int length2 = cipher.doFinal(decryptedBytes, length1);
|
final int length2 = cipher.doFinal(decryptedBytes, length1);
|
||||||
|
@ -63,11 +63,11 @@ public class KeyCrypterScryptTest {
|
|||||||
KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(scryptParameters);
|
KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(scryptParameters);
|
||||||
|
|
||||||
// Encrypt.
|
// Encrypt.
|
||||||
EncryptedData encryptedPrivateKey = keyCrypter.encrypt(TEST_BYTES1, keyCrypter.deriveKey(PASSWORD1));
|
EncryptedData data = keyCrypter.encrypt(TEST_BYTES1, keyCrypter.deriveKey(PASSWORD1));
|
||||||
assertNotNull(encryptedPrivateKey);
|
assertNotNull(data);
|
||||||
|
|
||||||
// Decrypt.
|
// Decrypt.
|
||||||
byte[] reborn = keyCrypter.decrypt(encryptedPrivateKey, keyCrypter.deriveKey(PASSWORD1));
|
byte[] reborn = keyCrypter.decrypt(data, keyCrypter.deriveKey(PASSWORD1));
|
||||||
log.debug("Original: " + Utils.HEX.encode(TEST_BYTES1));
|
log.debug("Original: " + Utils.HEX.encode(TEST_BYTES1));
|
||||||
log.debug("Reborn : " + Utils.HEX.encode(reborn));
|
log.debug("Reborn : " + Utils.HEX.encode(reborn));
|
||||||
assertEquals(Utils.HEX.encode(TEST_BYTES1), Utils.HEX.encode(reborn));
|
assertEquals(Utils.HEX.encode(TEST_BYTES1), Utils.HEX.encode(reborn));
|
||||||
@ -90,11 +90,11 @@ public class KeyCrypterScryptTest {
|
|||||||
String plainText = UUID.randomUUID().toString();
|
String plainText = UUID.randomUUID().toString();
|
||||||
CharSequence password = UUID.randomUUID().toString();
|
CharSequence password = UUID.randomUUID().toString();
|
||||||
|
|
||||||
EncryptedData encryptedPrivateKey = keyCrypter.encrypt(plainText.getBytes(), keyCrypter.deriveKey(password));
|
EncryptedData data = keyCrypter.encrypt(plainText.getBytes(), keyCrypter.deriveKey(password));
|
||||||
|
|
||||||
assertNotNull(encryptedPrivateKey);
|
assertNotNull(data);
|
||||||
|
|
||||||
byte[] reconstructedPlainBytes = keyCrypter.decrypt(encryptedPrivateKey,keyCrypter.deriveKey(password));
|
byte[] reconstructedPlainBytes = keyCrypter.decrypt(data,keyCrypter.deriveKey(password));
|
||||||
assertEquals(Utils.HEX.encode(plainText.getBytes()), Utils.HEX.encode(reconstructedPlainBytes));
|
assertEquals(Utils.HEX.encode(plainText.getBytes()), Utils.HEX.encode(reconstructedPlainBytes));
|
||||||
System.out.print('.');
|
System.out.print('.');
|
||||||
}
|
}
|
||||||
@ -128,11 +128,11 @@ public class KeyCrypterScryptTest {
|
|||||||
KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(scryptParameters);
|
KeyCrypterScrypt keyCrypter = new KeyCrypterScrypt(scryptParameters);
|
||||||
|
|
||||||
// Encrypt bytes.
|
// Encrypt bytes.
|
||||||
EncryptedData encryptedPrivateKey = keyCrypter.encrypt(TEST_BYTES1, keyCrypter.deriveKey(PASSWORD1));
|
EncryptedData data = keyCrypter.encrypt(TEST_BYTES1, keyCrypter.deriveKey(PASSWORD1));
|
||||||
assertNotNull(encryptedPrivateKey);
|
assertNotNull(data);
|
||||||
log.debug("\nEncrypterDecrypterTest: cipherBytes = \nlength = " + encryptedPrivateKey.encryptedBytes.length + "\n---------------\n" + Utils.HEX.encode(encryptedPrivateKey.encryptedBytes) + "\n---------------\n");
|
log.debug("\nEncrypterDecrypterTest: cipherBytes = \nlength = " + data.encryptedBytes.length + "\n---------------\n" + Utils.HEX.encode(data.encryptedBytes) + "\n---------------\n");
|
||||||
|
|
||||||
byte[] rebornPlainBytes = keyCrypter.decrypt(encryptedPrivateKey, keyCrypter.deriveKey(PASSWORD1));
|
byte[] rebornPlainBytes = keyCrypter.decrypt(data, keyCrypter.deriveKey(PASSWORD1));
|
||||||
|
|
||||||
log.debug("Original: " + Utils.HEX.encode(TEST_BYTES1));
|
log.debug("Original: " + Utils.HEX.encode(TEST_BYTES1));
|
||||||
log.debug("Reborn1 : " + Utils.HEX.encode(rebornPlainBytes));
|
log.debug("Reborn1 : " + Utils.HEX.encode(rebornPlainBytes));
|
||||||
@ -150,11 +150,11 @@ public class KeyCrypterScryptTest {
|
|||||||
byte[] plainBytes = new byte[i];
|
byte[] plainBytes = new byte[i];
|
||||||
random.nextBytes(plainBytes);
|
random.nextBytes(plainBytes);
|
||||||
|
|
||||||
EncryptedData encryptedPrivateKey = keyCrypter.encrypt(plainBytes, keyCrypter.deriveKey(PASSWORD1));
|
EncryptedData data = keyCrypter.encrypt(plainBytes, keyCrypter.deriveKey(PASSWORD1));
|
||||||
assertNotNull(encryptedPrivateKey);
|
assertNotNull(data);
|
||||||
//log.debug("\nEncrypterDecrypterTest: cipherBytes = \nlength = " + cipherBytes.length + "\n---------------\n" + Utils.HEX.encode(cipherBytes) + "\n---------------\n");
|
//log.debug("\nEncrypterDecrypterTest: cipherBytes = \nlength = " + cipherBytes.length + "\n---------------\n" + Utils.HEX.encode(cipherBytes) + "\n---------------\n");
|
||||||
|
|
||||||
byte[] rebornPlainBytes = keyCrypter.decrypt(encryptedPrivateKey, keyCrypter.deriveKey(PASSWORD1));
|
byte[] rebornPlainBytes = keyCrypter.decrypt(data, keyCrypter.deriveKey(PASSWORD1));
|
||||||
|
|
||||||
log.debug("Original: (" + i + ") " + Utils.HEX.encode(plainBytes));
|
log.debug("Original: (" + i + ") " + Utils.HEX.encode(plainBytes));
|
||||||
log.debug("Reborn1 : (" + i + ") " + Utils.HEX.encode(rebornPlainBytes));
|
log.debug("Reborn1 : (" + i + ") " + Utils.HEX.encode(rebornPlainBytes));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user