public static String getAddress(BigInteger publicKey) { return getAddress( Numeric.toHexStringWithPrefixZeroPadded(publicKey, PUBLIC_KEY_LENGTH_IN_HEX)); }
public static ECKeyPair createEcKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { return createEcKeyPair(secureRandom()); }
public static ECKeyPair createEcKeyPair(SecureRandom random) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { KeyPair keyPair = createSecp256k1KeyPair(random); return ECKeyPair.create(keyPair); }
@Test(expected = RuntimeException.class) public void testDeserializeInvalidKey() { Keys.deserialize(new byte[0]); } }
@Test public void testSerializeECKey() { assertThat(Keys.serialize(SampleKeys.KEY_PAIR), is(ENCODED)); }
@Test public void testDeserializeECKey() { assertThat(Keys.deserialize(ENCODED), is(SampleKeys.KEY_PAIR)); }
public static String getAddress(ECKeyPair ecKeyPair) { return getAddress(ecKeyPair.getPublicKey()); }
public static String generateNewWalletFile( String password, File destinationDirectory, boolean useFullScrypt) throws CipherException, IOException, InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { ECKeyPair ecKeyPair = Keys.createEcKeyPair(); return generateWalletFile(password, ecKeyPair, destinationDirectory, useFullScrypt); }
/** * Create a keypair using SECP-256k1 curve. * * <p>Private keypairs are encoded using PKCS8 * * <p>Private keys are encoded using X.509 */ static KeyPair createSecp256k1KeyPair() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { return createSecp256k1KeyPair(secureRandom()); }
public static Credentials create(ECKeyPair ecKeyPair) { String address = Numeric.prependHexPrefix(Keys.getAddress(ecKeyPair)); return new Credentials(ecKeyPair, address); }
@Test public void testCreateEcKeyPair() throws Exception { ECKeyPair ecKeyPair = Keys.createEcKeyPair(); assertThat(ecKeyPair.getPublicKey().signum(), is(1)); assertThat(ecKeyPair.getPrivateKey().signum(), is(1)); }
@Test public void testCreateSecp256k1KeyPair() throws Exception { KeyPair keyPair = Keys.createSecp256k1KeyPair(); PrivateKey privateKey = keyPair.getPrivate(); PublicKey publicKey = keyPair.getPublic(); assertNotNull(privateKey); assertNotNull(publicKey); assertThat(privateKey.getEncoded().length, is(144)); assertThat(publicKey.getEncoded().length, is(88)); }
@Test public void testGetAddressString() { assertThat(Keys.getAddress(SampleKeys.PUBLIC_KEY_STRING), is(SampleKeys.ADDRESS_NO_PREFIX)); }
private EthereumAccount(NETWORK network) throws Exception { this(network, Keys.createEcKeyPair(), BigInteger.ZERO); }
public static ECKeyPair createEcKeyPair(SecureRandom random) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { KeyPair keyPair = createSecp256k1KeyPair(random); return ECKeyPair.create(keyPair); }
@Test public void testGetAddressZeroPaddedAddress() { String publicKey = "0xa1b31be4d58a7ddd24b135db0da56a90fb5382077ae26b250e1dc9cd6232ce22" + "70f4c995428bc76aa78e522316e95d7834d725efc9ca754d043233af6ca90113"; assertThat(Keys.getAddress(publicKey), is("01c52b08330e05d731e38c856c1043288f7d9744")); }
public static ECKeyPair createEcKeyPair() throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException { return createEcKeyPair(secureRandom()); }
/** * Create a keypair using SECP-256k1 curve. * * <p>Private keypairs are encoded using PKCS8 * * <p>Private keys are encoded using X.509 */ static KeyPair createSecp256k1KeyPair() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException { return createSecp256k1KeyPair(secureRandom()); }
@Test public void testGetAddressSmallPublicKey() { byte[] address = Keys.getAddress( Numeric.toBytesPadded(BigInteger.valueOf(0x1234), Keys.PUBLIC_KEY_SIZE)); String expected = Numeric.toHexStringNoPrefix(address); assertThat(Keys.getAddress("0x1234"), equalTo(expected)); }
/** * 创建钱包 * * @param password 密码 */ public static void createWallet(String password) throws InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchProviderException, CipherException, JsonProcessingException { WalletFile walletFile; ECKeyPair ecKeyPair = Keys.createEcKeyPair(); walletFile = Wallet.createStandard(password, ecKeyPair); System.out.println("address " + walletFile.getAddress()); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); String jsonStr = objectMapper.writeValueAsString(walletFile); System.out.println("keystore json file " + jsonStr); }