Ethereum: Generating an address from a private key in Java?

Here is an example of how to create an ethereum address from the private key Java:

`Java

Bring org.betereum.crypto.*;

Public -Class Head {

Public Static Empty Main (String [] Args) {

// Create a New Private Key

PRIVATEKEY PRIVATEEKEY = New PrivateeKey (“some_private_key”);

// Get a der-coded private key

Byte [] derencodedprivatekey = privateekey.Geterencoded ();

// Create Ethereum address from a private key

Ethereumaddress ethereumaddress = new ethereumaddress (Dencodedprivatekey);

System.out.println (“Created Ethereum Address:” + EtherEdddress.Tostring ());

}

}

`

This example uses the “org.betereum.cryptopackage that is part of the Ethereum Java application. To use this package, you need to add the following dependency to the mavors project:

Xml

org.ethereum

Ethereum-Javapi

1.2.0-RC.2

`

In the ethereumaddress' class there is a builder who takes the private key of the der coded as an argument.

Note: This Example Creates A New Ethereum Address Every Time You Do It Unless You Edit The Code To Create Addresses From Existing Kees With A Key Derivative Function, Such As Ethereum's ECDSA. However, this is not recommended for use in production as it may be subsceptible to attacks.

HERE IS ANOTHER EXAMPLE THAT USES A DERIVATIVE CENTRAL:

Java

Bring org.betereum.crypto.*;

Public -Class Head {

Public Static Empty Main (String [] Args) {

// Create a New Private Key Using Ethereum ECDSA Algorithm

Privatekey Privatekey = New Privatekey (New Keypairbuilder (). SeedFrom (New ECDSarsa256SignAGAGAGLAt (

New ECDSARA256SignAsignAsignArameters (“Some_Private_Key”),

1, 1, 0, 0, 0,

10, 20, 30, 40, 50

)). Build ());

// Get a der-coded private key

Byte [] derencodedprivatekey = privateekey.Geterencoded ();

// Create Ethereum address from a private key

Ethereumaddress ethereumaddress = new ethereumaddress (Dencodedprivatekey);

System.out.println (“Created Ethereum Address:” + EtherEdddress.Tostring ());

}

}

`

This example produces a new ethereum address using the Ethereum ECDSA algorithm and the private key supplied. “Keypairbuilder ‘Class is used to create an ECDSA pair from the private key.

Ripple Layer Consensus Mechanism

Leave a Comment