Search in sources :

Example 1 with Mnemonic

use of com.hedera.hashgraph.sdk.Mnemonic in project hedera-sdk-java by hashgraph.

the class GenerateKeyWithMnemonicExample method main.

public static void main(String[] args) {
    Mnemonic mnemonic = Mnemonic.generate24();
    PrivateKey privateKey;
    try {
        privateKey = mnemonic.toPrivateKey();
    } catch (BadMnemonicException e) {
        throw new Error(e.reason.toString());
    }
    PublicKey publicKey = privateKey.getPublicKey();
    Mnemonic mnemonic12 = Mnemonic.generate12();
    PrivateKey privateKey12;
    try {
        privateKey12 = mnemonic12.toPrivateKey();
    } catch (BadMnemonicException e) {
        throw new Error(e.reason.toString());
    }
    PublicKey publicKey12 = privateKey12.getPublicKey();
    System.out.println("mnemonic 24 word = " + mnemonic);
    System.out.println("private key = " + privateKey);
    System.out.println("public key = " + publicKey);
    System.out.println("mnemonic 12 word = " + mnemonic12);
    System.out.println("private key = " + privateKey12);
    System.out.println("public key = " + publicKey12);
}
Also used : PrivateKey(com.hedera.hashgraph.sdk.PrivateKey) PublicKey(com.hedera.hashgraph.sdk.PublicKey) Mnemonic(com.hedera.hashgraph.sdk.Mnemonic) BadMnemonicException(com.hedera.hashgraph.sdk.BadMnemonicException)

Aggregations

BadMnemonicException (com.hedera.hashgraph.sdk.BadMnemonicException)1 Mnemonic (com.hedera.hashgraph.sdk.Mnemonic)1 PrivateKey (com.hedera.hashgraph.sdk.PrivateKey)1 PublicKey (com.hedera.hashgraph.sdk.PublicKey)1