本文整理汇总了Java中net.bither.bitherj.utils.PrivateKeyUtil.encrypt方法的典型用法代码示例。如果您正苦于以下问题:Java PrivateKeyUtil.encrypt方法的具体用法?Java PrivateKeyUtil.encrypt怎么用?Java PrivateKeyUtil.encrypt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.bither.bitherj.utils.PrivateKeyUtil
的用法示例。
在下文中一共展示了PrivateKeyUtil.encrypt方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addPrivateKeyByRandomWithPassphras
import net.bither.bitherj.utils.PrivateKeyUtil; //导入方法依赖的package包/类
public static List<Address> addPrivateKeyByRandomWithPassphras(IUEntropy iuEntropy, CharSequence password, int count) {
PeerUtil.stopPeer();
List<Address> addressList = new ArrayList<Address>();
for (int i = 0; i < count; i++) {
XRandom xRandom = new XRandom(iuEntropy);
ECKey ecKey = ECKey.generateECKey(xRandom);
ecKey = PrivateKeyUtil.encrypt(ecKey, password);
Address address = new Address(ecKey.toAddress(),
ecKey.getPubKey(), PrivateKeyUtil.getEncryptedString(ecKey), ecKey.isFromXRandom());
ecKey.clearPrivateKey();
addressList.add(address);
AddressManager.getInstance().addAddress(address);
}
PeerUtil.startPeer();
if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
BackupUtil.backupColdKey(false);
} else {
BackupUtil.backupHotKey();
}
return addressList;
}
示例2: addPrivateKeyByRandomWithPassphras
import net.bither.bitherj.utils.PrivateKeyUtil; //导入方法依赖的package包/类
public static List<Address> addPrivateKeyByRandomWithPassphras(BlockchainService service, IUEntropy iuEntropy, CharSequence password, int count) {
if (service != null) {
service.stopAndUnregister();
}
List<Address> addressList = new ArrayList<Address>();
for (int i = 0; i < count; i++) {
XRandom xRandom = new XRandom(iuEntropy);
ECKey ecKey = ECKey.generateECKey(xRandom);
ecKey = PrivateKeyUtil.encrypt(ecKey, password);
Address address = new Address(ecKey.toAddress(),
ecKey.getPubKey(), PrivateKeyUtil.getEncryptedString(ecKey), true, ecKey.isFromXRandom());
ecKey.clearPrivateKey();
addressList.add(address);
AddressManager.getInstance().addAddress(address);
}
if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
BackupUtil.backupColdKey(false);
} else {
BackupUtil.backupHotKey();
}
if (service != null) {
service.startAndRegister();
}
return addressList;
}
示例3: addECKey
import net.bither.bitherj.utils.PrivateKeyUtil; //导入方法依赖的package包/类
private Address addECKey(ECKey ecKey) {
String encryptedPrivateString;
if (importPrivateKeyType == ImportPrivateKeyType.BitherQrcode) {
encryptedPrivateString = QRCodeUtil.getNewVersionEncryptPrivKey(content);
} else {
ecKey = PrivateKeyUtil.encrypt(ecKey, password);
encryptedPrivateString = PrivateKeyUtil.getEncryptedString(ecKey);
}
Address address = new Address(ecKey.toAddress(), ecKey.getPubKey(), encryptedPrivateString
, false, ecKey.isFromXRandom());
if (AddressManager.getInstance().getWatchOnlyAddresses().contains(address)) {
password.wipe();
importError(CAN_NOT_IMPORT_BITHER_COLD_PRIVATE_KEY);
return null;
} else if (AddressManager.getInstance().getPrivKeyAddresses().contains(address)) {
password.wipe();
importError(PRIVATE_KEY_ALREADY_EXISTS);
return null;
} else {
if (importPrivateKeyType == ImportPrivateKeyType.BitherQrcode) {
PasswordSeed passwordSeed = PasswordSeed.getPasswordSeed();
if (passwordSeed != null && !passwordSeed.checkPassword(password)) {
password.wipe();
importError(PASSWORD_IS_DIFFEREND_LOCAL);
return null;
}
} else {
password.wipe();
}
return address;
}
}
示例4: run
import net.bither.bitherj.utils.PrivateKeyUtil; //导入方法依赖的package包/类
@Override
public void run() {
startGeneratingTime = System.currentTimeMillis();
onProgress(startProgress);
SecureCharSequence password = passwordGetter.getPassword();
boolean success = false;
final ArrayList<String> addressStrs = new ArrayList<String>();
double progress = startProgress;
double itemProgress = (1.0 - startProgress - saveProgress) / (double) targetCount;
try {
entropyCollector.start();
PeerUtil.stopPeer();
java.util.List<Address> addressList = new ArrayList<Address>();
for (int i = 0;
i < targetCount;
i++) {
if (cancelRunnable != null) {
finishGenerate();
SwingUtilities.invokeLater(cancelRunnable);
return;
}
XRandom xRandom = new XRandom(entropyCollector);
ECKey ecKey = ECKey.generateECKey(xRandom);
ecKey.setFromXRandom(true);
progress += itemProgress * progressKeyRate;
onProgress(progress);
if (cancelRunnable != null) {
finishGenerate();
SwingUtilities.invokeLater(cancelRunnable);
return;
}
// start encrypt
ecKey = PrivateKeyUtil.encrypt(ecKey, password);
Address address = new Address(ecKey.toAddress(), ecKey.getPubKey(),
PrivateKeyUtil.getEncryptedString(ecKey), ecKey.isFromXRandom());
ecKey.clearPrivateKey();
addressList.add(address);
addressStrs.add(address.getAddress());
progress += itemProgress * progressEntryptRate;
onProgress(progress);
}
entropyCollector.stop();
passwordGetter.wipe();
if (cancelRunnable != null) {
finishGenerate();
SwingUtilities.invokeLater(cancelRunnable);
return;
}
KeyUtil.addAddressListByDesc(addressList);
success = true;
} catch (Exception e) {
e.printStackTrace();
}
finishGenerate();
if (success) {
while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) {
}
onProgress(1);
didSuccess(addressStrs);
} else {
onFailed();
}
}
示例5: runWithService
import net.bither.bitherj.utils.PrivateKeyUtil; //导入方法依赖的package包/类
@Override
public void runWithService(BlockchainService service) {
boolean success = false;
final ArrayList<String> addressStrs = new ArrayList<String>();
double progress = startProgress;
double itemProgress = (1.0 - startProgress - saveProgress) / (double) targetCount;
try {
entropyCollector.start();
if (service != null) {
service.stopAndUnregister();
}
XRandom xRandom = new XRandom(entropyCollector);
List<Address> addressList = new ArrayList<Address>();
for (int i = 0;
i < targetCount;
i++) {
if (cancelRunnable != null) {
finishGenerate(service);
runOnUiThread(cancelRunnable);
return;
}
ECKey ecKey = ECKey.generateECKey(xRandom);
ecKey.setFromXRandom(true);
progress += itemProgress * progressKeyRate;
onProgress(progress);
if (cancelRunnable != null) {
finishGenerate(service);
runOnUiThread(cancelRunnable);
return;
}
// start encrypt
ecKey = PrivateKeyUtil.encrypt(ecKey, password);
Address address = new Address(ecKey.toAddress(), ecKey.getPubKey(),
PrivateKeyUtil.getEncryptedString(ecKey), true, ecKey.isFromXRandom());
ecKey.clearPrivateKey();
addressList.add(address);
addressStrs.add(address.getAddress());
progress += itemProgress * progressEntryptRate;
onProgress(progress);
}
entropyCollector.stop();
password.wipe();
password = null;
if (cancelRunnable != null) {
finishGenerate(service);
runOnUiThread(cancelRunnable);
return;
}
KeyUtil.addAddressListByDesc(service, addressList);
success = true;
} catch (Exception e) {
e.printStackTrace();
}
finishGenerate(service);
if (success) {
while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) {
}
onProgress(1);
onSuccess(addressStrs);
} else {
onFailed();
}
}