/** * Returns an ECKey created from this encoded private key. */ public ECKey getKey() { final ECKey key = ECKey.fromPrivate(bytes); return compressed ? key : key.decompress(); }
/** * Returns an ECKey created from this encoded private key. */ public ECKey getKey() { final ECKey key = ECKey.fromPrivate(bytes); return compressed ? key : key.decompress(); }
/** * Returns an ECKey created from this encoded private key. */ public ECKey getKey() { final ECKey key = ECKey.fromPrivate(bytes); return compressed ? key : key.decompress(); }
private TypedKey getFromWifKey() { ImmutableList.Builder<CoinType> builder = ImmutableList.builder(); for (CoinType type : CoinID.getSupportedCoins()) { if (version == type.getDumpedPrivateKeyHeader()) { builder.add(type); } } final ECKey key = compressed ? ECKey.fromPrivate(content) : ECKey.fromPrivate(content).decompress(); return new TypedKey(builder.build(), key); }
private TypedKey getFromWifKey() { ImmutableList.Builder<CoinType> builder = ImmutableList.builder(); for (CoinType type : CoinID.getSupportedCoins()) { if (version == type.getDumpedPrivateKeyHeader()) { builder.add(type); } } final ECKey key = compressed ? ECKey.fromPrivate(content) : ECKey.fromPrivate(content).decompress(); return new TypedKey(builder.build(), key); }
private TypedKey getFromMiniKey() { final ECKey key = ECKey.fromPrivate(content).decompress(); return new TypedKey(CoinID.getSupportedCoins(), key); } }
private TypedKey getFromMiniKey() { final ECKey key = ECKey.fromPrivate(content).decompress(); return new TypedKey(CoinID.getSupportedCoins(), key); } }
/** * Create a decrypted private key with the keyCrypter and AES key supplied. Note that if the aesKey is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param keyCrypter The keyCrypter that specifies exactly how the decrypted bytes are created. * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyCrypter keyCrypter, KeyParameter aesKey) throws KeyCrypterException { checkNotNull(keyCrypter); // Check that the keyCrypter matches the one used to encrypt the keys, if set. if (this.keyCrypter != null && !this.keyCrypter.equals(keyCrypter)) throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it"); checkState(encryptedPrivateKey != null, "This key is not encrypted"); byte[] unencryptedPrivateKey = keyCrypter.decrypt(encryptedPrivateKey, aesKey); ECKey key = ECKey.fromPrivate(unencryptedPrivateKey); if (!isCompressed()) key = key.decompress(); if (!Arrays.equals(key.getPubKey(), getPubKey())) throw new KeyCrypterException("Provided AES key is wrong"); key.setCreationTimeSeconds(creationTimeSeconds); return key; }
/** * Create a decrypted private key with the keyCrypter and AES key supplied. Note that if the aesKey is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param keyCrypter The keyCrypter that specifies exactly how the decrypted bytes are created. * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyCrypter keyCrypter, KeyParameter aesKey) throws KeyCrypterException { checkNotNull(keyCrypter); // Check that the keyCrypter matches the one used to encrypt the keys, if set. if (this.keyCrypter != null && !this.keyCrypter.equals(keyCrypter)) throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it"); checkState(encryptedPrivateKey != null, "This key is not encrypted"); byte[] unencryptedPrivateKey = keyCrypter.decrypt(encryptedPrivateKey, aesKey); ECKey key = ECKey.fromPrivate(unencryptedPrivateKey); if (!isCompressed()) key = key.decompress(); if (!Arrays.equals(key.getPubKey(), getPubKey())) throw new KeyCrypterException("Provided AES key is wrong"); key.setCreationTimeSeconds(creationTimeSeconds); return key; }
/** * Create a decrypted private key with the keyCrypter and AES key supplied. Note that if the aesKey is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param keyCrypter The keyCrypter that specifies exactly how the decrypted bytes are created. * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyCrypter keyCrypter, KeyParameter aesKey) throws KeyCrypterException { checkNotNull(keyCrypter); // Check that the keyCrypter matches the one used to encrypt the keys, if set. if (this.keyCrypter != null && !this.keyCrypter.equals(keyCrypter)) throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it"); checkState(encryptedPrivateKey != null, "This key is not encrypted"); byte[] unencryptedPrivateKey = keyCrypter.decrypt(encryptedPrivateKey, aesKey); ECKey key = ECKey.fromPrivate(unencryptedPrivateKey); if (!isCompressed()) key = key.decompress(); if (!Arrays.equals(key.getPubKey(), getPubKey())) throw new KeyCrypterException("Provided AES key is wrong"); key.setCreationTimeSeconds(creationTimeSeconds); return key; }
/** * Create a decrypted private key with the keyCrypter and AES key supplied. Note that if the aesKey is wrong, this * has some chance of throwing KeyCrypterException due to the corrupted padding that will result, but it can also * just yield a garbage key. * * @param keyCrypter The keyCrypter that specifies exactly how the decrypted bytes are created. * @param aesKey The KeyParameter with the AES encryption key (usually constructed with keyCrypter#deriveKey and cached). */ public ECKey decrypt(KeyCrypter keyCrypter, KeyParameter aesKey) throws KeyCrypterException { checkNotNull(keyCrypter); // Check that the keyCrypter matches the one used to encrypt the keys, if set. if (this.keyCrypter != null && !this.keyCrypter.equals(keyCrypter)) throw new KeyCrypterException("The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it"); checkState(encryptedPrivateKey != null, "This key is not encrypted"); byte[] unencryptedPrivateKey = keyCrypter.decrypt(encryptedPrivateKey, aesKey); ECKey key = ECKey.fromPrivate(unencryptedPrivateKey); if (!isCompressed()) key = key.decompress(); if (!Arrays.equals(key.getPubKey(), getPubKey())) throw new KeyCrypterException("Provided AES key is wrong"); key.setCreationTimeSeconds(creationTimeSeconds); return key; }
@Test public void testGetPrivateKeyAsHex() throws Exception { ECKey key = ECKey.fromPrivate(BigInteger.TEN).decompress(); // An example private key. assertEquals("000000000000000000000000000000000000000000000000000000000000000a", key.getPrivateKeyAsHex()); }
@Test public void testGetPublicKeyAsHex() throws Exception { ECKey key = ECKey.fromPrivate(BigInteger.TEN).decompress(); // An example private key. assertEquals("04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7", key.getPublicKeyAsHex()); }
@Test public void testToString() throws Exception { ECKey key = ECKey.fromPrivate(BigInteger.TEN).decompress(); // An example private key. NetworkParameters params = MainNetParams.get(); assertEquals("ECKey{pub HEX=04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7, isEncrypted=false, isPubKeyOnly=false}", key.toString()); assertEquals("ECKey{pub HEX=04a0434d9e47f3c86235477c7b1ae6ae5d3442d49b1943c2b752a68e2a47e247c7893aba425419bc27a3b6c7e693a24c696f794c2ed877a1593cbee53b037368d7, priv HEX=000000000000000000000000000000000000000000000000000000000000000a, priv WIF=5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreBoNWTw6, isEncrypted=false, isPubKeyOnly=false}", key.toStringWithPrivate(params)); }
@Test public void testPublicKeysAreEqual() { ECKey key = new ECKey(); ECKey pubKey1 = ECKey.fromPublicOnly(key.getPubKeyPoint()); assertTrue(pubKey1.isCompressed()); ECKey pubKey2 = pubKey1.decompress(); assertEquals(pubKey1, pubKey2); assertEquals(pubKey1.hashCode(), pubKey2.hashCode()); } }