本文整理汇总了Java中com.google.bitcoin.crypto.KeyCrypter.deriveKey方法的典型用法代码示例。如果您正苦于以下问题:Java KeyCrypter.deriveKey方法的具体用法?Java KeyCrypter.deriveKey怎么用?Java KeyCrypter.deriveKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.bitcoin.crypto.KeyCrypter
的用法示例。
在下文中一共展示了KeyCrypter.deriveKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: encrypt
import com.google.bitcoin.crypto.KeyCrypter; //导入方法依赖的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;
}
示例2: setPasscode
import com.google.bitcoin.crypto.KeyCrypter; //导入方法依赖的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");
}