Search in sources :

Example 1 with CipherException

use of org.bcos.web3j.crypto.CipherException in project web3sdk by FISCO-BCOS.

the class WalletUpdater method run.

private void run(String walletFileLocation) {
    File walletFile = new File(walletFileLocation);
    Credentials credentials = getCredentials(walletFile);
    console.printf("Wallet for address " + credentials.getAddress() + " loaded\n");
    String newPassword = getPassword("Please enter a new wallet file password: ");
    String destinationDir = getDestinationDir();
    File destination = createDir(destinationDir);
    try {
        String walletFileName = WalletUtils.generateWalletFile(newPassword, credentials.getEcKeyPair(), destination, true);
        console.printf("New wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n");
    } catch (CipherException | IOException e) {
        exitError(e);
    }
    String delete = console.readLine("Would you like to delete your existing wallet file (Y/N)? [N]: ");
    if (delete.toUpperCase().equals("Y")) {
        if (!walletFile.delete()) {
            exitError("Unable to remove wallet file\n");
        } else {
            console.printf("Deleted previous wallet file: %s\n", walletFile.getName());
        }
    }
}
Also used : CipherException(org.bcos.web3j.crypto.CipherException) IOException(java.io.IOException) File(java.io.File) Credentials(org.bcos.web3j.crypto.Credentials)

Example 2 with CipherException

use of org.bcos.web3j.crypto.CipherException in project web3sdk by FISCO-BCOS.

the class KeyImporter method createWalletFile.

private void createWalletFile(String privateKey) {
    if (!WalletUtils.isValidPrivateKey(privateKey)) {
        exitError("Invalid private key specified, must be " + PRIVATE_KEY_LENGTH_IN_HEX + " digit hex value");
    }
    Credentials credentials = Credentials.create(privateKey);
    String password = getPassword("Please enter a wallet file password: ");
    String destinationDir = getDestinationDir();
    File destination = createDir(destinationDir);
    try {
        String walletFileName = WalletUtils.generateWalletFile(password, credentials.getEcKeyPair(), destination, true);
        console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n");
    } catch (CipherException | IOException e) {
        exitError(e);
    }
}
Also used : CipherException(org.bcos.web3j.crypto.CipherException) IOException(java.io.IOException) File(java.io.File) Credentials(org.bcos.web3j.crypto.Credentials)

Example 3 with CipherException

use of org.bcos.web3j.crypto.CipherException in project web3sdk by FISCO-BCOS.

the class WalletCreator method run.

private void run() {
    String password = getPassword("Please enter a wallet file password: ");
    String destinationDir = getDestinationDir();
    File destination = createDir(destinationDir);
    try {
        String walletFileName = WalletUtils.generateFullNewWalletFile(password, destination);
        console.printf("Wallet file " + walletFileName + " successfully created in: " + destinationDir + "\n");
    } catch (CipherException | IOException | InvalidAlgorithmParameterException | NoSuchAlgorithmException | NoSuchProviderException e) {
        Console.exitError(e);
    }
}
Also used : InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CipherException(org.bcos.web3j.crypto.CipherException) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) NoSuchProviderException(java.security.NoSuchProviderException) File(java.io.File)

Aggregations

File (java.io.File)3 IOException (java.io.IOException)3 CipherException (org.bcos.web3j.crypto.CipherException)3 Credentials (org.bcos.web3j.crypto.Credentials)2 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 NoSuchProviderException (java.security.NoSuchProviderException)1