use of utils.security.DecryptionException in project jdchain-core by blockchain-jd-com.
the class KeyGenCommand method readKey.
/**
* 读取密钥; <br>
* 如果是私钥,则需要输入密码;
*
* @param keyFile
*/
public static void readKey(String keyFile, boolean decrypting) {
String base58KeyString = FileUtils.readText(keyFile);
byte[] keyBytes = Base58Utils.decode(base58KeyString);
if (KeyGenUtils.isPubKeyBytes(keyBytes)) {
if (decrypting) {
// Try reading pubKey;
PubKey pubKey = decodePubKey(keyBytes);
ConsoleUtils.info("======================== pub key ========================\r\n" + "[%s]\r\n" + "Raw:[%s][%s]\r\n", base58KeyString, pubKey.getAlgorithm(), Base58Utils.encode(pubKey.toBytes()));
} else {
ConsoleUtils.info("======================== pub key ========================\r\n" + "[%s]\r\n", base58KeyString);
}
return;
} else if (KeyGenUtils.isPrivKeyBytes(keyBytes)) {
// Try reading privKye;
try {
if (decrypting) {
byte[] pwdBytes = readPassword();
PrivKey privKey = decryptedPrivKeyBytes(keyBytes, pwdBytes);
ConsoleUtils.info("======================== priv key ========================\r\n" + "[%s]\r\n" + "Raw:[%s][%s]\r\n", base58KeyString, privKey.getAlgorithm(), Base58Utils.encode(privKey.toBytes()));
} else {
ConsoleUtils.info("======================== priv key ========================\r\n[%s]\r\n", base58KeyString);
}
} catch (DecryptionException e) {
ConsoleUtils.error("Invalid password!");
}
return;
} else {
ConsoleUtils.error("Unknow key!!");
return;
}
}
Aggregations