本文整理汇总了Java中com.google.bitcoin.crypto.KeyCrypterScrypt.SALT_LENGTH属性的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypterScrypt.SALT_LENGTH属性的具体用法?Java KeyCrypterScrypt.SALT_LENGTH怎么用?Java KeyCrypterScrypt.SALT_LENGTH使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.google.bitcoin.crypto.KeyCrypterScrypt
的用法示例。
在下文中一共展示了KeyCrypterScrypt.SALT_LENGTH属性的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
@Before
@Override
public void setUp() throws Exception {
super.setUp();
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
encryptedWallet = new Wallet(params, keyCrypter);
aesKey = keyCrypter.deriveKey(PASSWORD1);
wrongAesKey = keyCrypter.deriveKey(WRONG_PASSWORD);
ECKey myEncryptedKey = encryptedWallet.addNewEncryptedKey(keyCrypter, aesKey);
myEncryptedAddress = myEncryptedKey.toAddress(params);
}
示例2: setUp
@Before
@Override
public void setUp() throws Exception {
super.setUp();
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
encryptedWallet = new Wallet(params, keyCrypter);
encryptedMixedWallet = new Wallet(params, keyCrypter);
aesKey = keyCrypter.deriveKey(PASSWORD1);
wrongAesKey = keyCrypter.deriveKey(WRONG_PASSWORD);
ECKey myEncryptedKey = encryptedWallet.addNewEncryptedKey(keyCrypter, aesKey);
myEncryptedAddress = myEncryptedKey.toAddress(params);
encryptedMixedWallet.addKey(new ECKey());
ECKey myEncryptedKey2 = encryptedMixedWallet.addNewEncryptedKey(keyCrypter, aesKey);
myEncryptedAddress2 = myEncryptedKey2.toAddress(params);
}
示例3: setUp
@Before
public void setUp() throws Exception {
secureRandom = new SecureRandom();
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
BriefLogFormatter.init();
}
示例4: encryptionDecryptionHomogenousKeys
@Test
public void encryptionDecryptionHomogenousKeys() throws Exception {
// Check the wallet is currently encrypted
assertTrue("Wallet is not an encrypted wallet", encryptedWallet.getEncryptionType() == EncryptionType.ENCRYPTED_SCRYPT_AES);
// Try added an ECKey that was encrypted with a differenct ScryptParameters (i.e. a non-homogenous key).
// This is not allowed as the ScryptParameters is stored at the Wallet level.
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
KeyCrypter keyCrypterDifferent = new KeyCrypterScrypt(scryptParameters);
ECKey ecKeyDifferent = new ECKey();
ecKeyDifferent = ecKeyDifferent.encrypt(keyCrypterDifferent, aesKey);
Iterable<ECKey> keys = encryptedWallet.getKeys();
Iterator iterator = keys.iterator();
boolean oneKey = iterator.hasNext();
iterator.next();
assertTrue("Wrong number of keys in wallet before key addition", oneKey && !iterator.hasNext());
try {
encryptedWallet.addKey(ecKeyDifferent);
fail("AddKey should have thrown an EncrypterDecrypterException but did not.");
} catch (KeyCrypterException ede) {
// Expected behaviour.
}
keys = encryptedWallet.getKeys();
iterator = keys.iterator();
oneKey = iterator.hasNext();
iterator.next();
assertTrue("Wrong number of keys in wallet after key addition", oneKey && !iterator.hasNext());
}
示例5: setPasscode
public static void setPasscode(Context context,
WalletService walletService,
String passcode,
boolean isChange) {
WalletApplication wallapp =
(WalletApplication) context.getApplicationContext();
KeyParameter oldAesKey = wallapp.mAesKey;
mLogger.info("setPasscode starting");
byte[] salt;
if (isChange) {
// Reuse our salt (better chance of recovering if
// we are between passcode values).
salt = readSalt(context);
} else {
// Create salt and write to file.
SecureRandom secureRandom = new SecureRandom();
salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
writeSalt(context, salt);
}
KeyCrypter keyCrypter = getKeyCrypter(salt);
KeyParameter aesKey = keyCrypter.deriveKey(passcode);
if (isChange) {
walletService.changePasscode(oldAesKey, keyCrypter, aesKey);
}
// Set up the application context with credentials.
wallapp.mPasscode = passcode;
wallapp.mKeyCrypter = keyCrypter;
wallapp.mAesKey = aesKey;
mLogger.info("setPasscode finished");
}
示例6: setUp
@Before
public void setUp() throws Exception {
SecureRandom secureRandom = new SecureRandom();
byte[] salt = new byte[KeyCrypterScrypt.SALT_LENGTH];
secureRandom.nextBytes(salt);
Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters
.newBuilder().setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
keyCrypter = new KeyCrypterScrypt(scryptParameters);
}