# Use Crypto Utilities
You can work with the Private Key, Public Key, or Address methods.
# Private Key
You can create a private key from:
- Seed phrase.
- Randomly generated seed phrase.
- Randomly generated seed phrase with nonce 2.
- Seed bytes.
- Randomly generated seed bytes.
- Bytes.
- Encoded string.
# Create Private Key from Seed Phrase
package com.example;
// Necessary import.
import com.wavesplatform.transactions.account.PrivateKey;
public class CreatePrivateKeyFromSeedPhrase {
public static void main(String[] args) {
// Specify your account's seed phrase.
String seedPhrase = "PASTE A SEED PHRASE";
// Creation of the private key from the seed phrase.
PrivateKey accountPrivateKey = PrivateKey.fromSeed(seedPhrase);
// Print the output.
System.out.println("Sender's Private Key: " + accountPrivateKey);
}
}
# Generate Random Seed Phrase and Private Key
package com.example;
// Necessary imports.
import com.wavesplatform.crypto.Crypto;
import com.wavesplatform.transactions.account.PrivateKey;
public class GenerateRandomPrivateKey {
public static void main(String[] args) {
// Generaton of a random seed phrase.
String seed = Crypto.getRandomSeedPhrase();
// Creation of the private key from the seed phrase.
PrivateKey senderPrivateKey = PrivateKey.fromSeed(seed);
// Print the output.
System.out.println("Seed Phrase: " + seed);
System.out.println("Sender's Private Key: " + senderPrivateKey);
}
}
# Generate Random Seed Phrase with Nonce 2
package com.example;
// Necessary imports.
import com.wavesplatform.crypto.Crypto;
import com.wavesplatform.transactions.account.PrivateKey;
public class GeneratePrivateKeyWithNonce2 {
public static void main(String[] args) {
// Generaton of a random seed phrase.
String seed = Crypto.getRandomSeedPhrase();
// Creation of the private key from the seed phrase, with the nonce equal to 2.
PrivateKey senderPrivateKey = PrivateKey.fromSeed(seed, 2);
// Print the output.
System.out.println("Seed Phrase: " + seed);
System.out.println("Sender's Private Key: " + senderPrivateKey);
}
}
# Create Private Key from Seed Bytes
package com.example;
// Necessary import.
import com.wavesplatform.transactions.account.PrivateKey;
public class CreatePrivateKeyFromSeedBytes {
public static void main(String[] args) {
// Creation of a byte array.
byte[] seed = new byte[] { 1, 2, 3, 4, 5, 6, 7 }; // Byte array example.
// Creation of the private key from the seed bytes.
PrivateKey privateKeyFromBytes = PrivateKey.fromSeed(seed);
// Print the output.
System.out.println("Sender's Private Key: " + privateKeyFromBytes);
}
}
# Create Private Key from Randomly Generated Seed Bytes
package com.example;
// Necessary imports.
import com.wavesplatform.crypto.Crypto;
import com.wavesplatform.transactions.account.PrivateKey;
public class CreatePrivateKeyFromRandomSeedBytes {
public static void main(String[] args) {
// Generation of random seed bytes.
byte[] randomSeedBytes = Crypto.getRandomSeedBytes();
// Creation of the private key from the randomly generated seed bytes.
PrivateKey senderPrivateKey = PrivateKey.fromSeed(randomSeedBytes);
// Print the output.
System.out.println("Sender's Private Key: " + senderPrivateKey);
}
}
# Create Private Key from Bytes
package com.example;
// Necessary import.
import com.wavesplatform.transactions.account.PrivateKey;
public class CreatePrivateKeyFromBytes {
public static void main(String[] args) {
// Creation of a byte array.
byte[] bytes = {56, -3, 37, 64, 2, 38, 78, 37, -98, -45, -23, 117, 14, 88, 20, 42, -9, 21, 55, 87, 117, -8, -81, 77, 77, -99, -87, -23, 7, 116, -99, -20}; // Bytes example.
// Creation of the private key from the bytes.
PrivateKey senderPrivateKey = PrivateKey.as(bytes);
// Print the output.
System.out.println("Sender's Private Key: " + senderPrivateKey);
}
}
# Create Private Key from an Encoded String
package com.example;
// Necessary import.
import com.wavesplatform.transactions.account.PrivateKey;
public class CreatePrivateKeyFromEncodedString {
public static void main(String[] args) {
// Creation of a Base58 string.
String base58String = "A5u9Ugt2nG1rWfLkL7pzZrtkP8LgF2rD3g1XBjsF8ZzV"; // Base58 string example.
// Creation of the private key from the encoded string.
PrivateKey senderPrivateKey = PrivateKey.as(base58String);
// Print the output.
System.out.println("Sender's Private Key: " + senderPrivateKey);
}
}
# Public Key
You can create a public key from a private key:
- Generate the private key.
- Place the following code after the private key generation:
// Create the public key from the private key. PublicKey publicKey = privateKey.publicKey(); // Print the pubic key. System.out.println("Sender's Public Key: " + publicKey);
# Address
You can create an address from a public key:
Place the following code after the public key generation:
NOTE: Ensure importing the following dependencies:
import com.wavesplatform.transactions.common.ChainId;
import com.wavesplatform.transactions.account.Address;
/* * Define the network of your wallet: * - Use `ChainId.MAINNET` for Mainnet. * - Use `ChainId.TESTNET` for Testnet. * - Use `ChainId.STAGENET` for StageNet. */ Address senderAddress = Address.from(ChainId.TESTNET, senderPublicKey); System.out.println("Sender's Address: " + senderAddress);