本文整理汇总了Java中com.google.bitcoin.crypto.KeyCrypterScrypt类的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypterScrypt类的具体用法?Java KeyCrypterScrypt怎么用?Java KeyCrypterScrypt使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KeyCrypterScrypt类属于com.google.bitcoin.crypto包,在下文中一共展示了KeyCrypterScrypt类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@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
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@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: encrypt
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
/**
* Convenience wrapper around {@link Wallet#encrypt(com.google.bitcoin.crypto.KeyCrypter,
* org.spongycastle.crypto.params.KeyParameter)} which uses the default Scrypt key derivation algorithm and
* parameters, derives a key from the given password and returns the created key.
*/
public KeyParameter encrypt(CharSequence password) {
checkNotNull(password);
checkArgument(password.length() > 0);
KeyCrypter scrypt = new KeyCrypterScrypt();
KeyParameter derivedKey = scrypt.deriveKey(password);
encrypt(scrypt, derivedKey);
return derivedKey;
}
示例4: setUp
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@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();
}
示例5: encryptionDecryptionHomogenousKeys
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@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());
}
示例6: setPasscode
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
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");
}
示例7: getKeyCrypter
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
public static KeyCrypter getKeyCrypter(byte[] salt) {
Protos.ScryptParameters.Builder scryptParametersBuilder =
Protos.ScryptParameters.newBuilder()
.setSalt(ByteString.copyFrom(salt));
ScryptParameters scryptParameters = scryptParametersBuilder.build();
return new KeyCrypterScrypt(scryptParameters);
}
示例8: setUp
import com.google.bitcoin.crypto.KeyCrypterScrypt; //导入依赖的package包/类
@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);
}