Private Key

Keystore to private key by web3j

  • keystore
    {
        "address":"5b7ca0361e23e18a8f91fd1c5890d50adc8a53c5",
        "crypto":{
            "cipher":"aes-128-ctr",
            "ciphertext":"88655666a1eb7476fae05b2f58f84974f0316e9861a10e93f88763d480a3489f",
            "cipherparams":{
                "iv":"bd0236c1c69de7800c2e17899de439e8"
            },
            "kdf":"scrypt",
            "kdfparams":{
                "dklen":32,
                "n":8192,
                "p":1,
                "r":8,
                "salt":"e1a68d9bbb4991b1b067b049277cc279666d5b66b5b0f87dbe7fd62c9e2654f6"
            },
            "mac":"e380dbb051072576140cbf1a97fd14d616cf8b012f0c7228ecfa966629664592"
        },
        "id":"ab17bbfa-5084-4455-91cc-0ba2644810dd",
        "version":3
    }
    
  • test

    import static org.assertj.core.api.Assertions.assertThat;
    
    import com.google.gson.Gson;
    import com.isuncloud.tidewallet.eth.InputData;
    import org.junit.Test;
    import org.web3j.crypto.Wallet;
    import org.web3j.crypto.WalletFile;
    
    public class Test {
    
      @Test
      public void fromKeystore() throws Exception {
        // arrange
        final WalletFile keystore = new WalletFile();
        keystore.setVersion(3);
        keystore.setId("ab17bbfa-5084-4455-91cc-0ba2644810dd");
        keystore.setAddress("5b7ca0361e23e18a8f91fd1c5890d50adc8a53c5");
        final WalletFile.Crypto crypto = new WalletFile.Crypto();
        crypto.setCiphertext("88655666a1eb7476fae05b2f58f84974f0316e9861a10e93f88763d480a3489f");
        final WalletFile.CipherParams cipherparams = new WalletFile.CipherParams();
        cipherparams.setIv("bd0236c1c69de7800c2e17899de439e8");
        crypto.setCipherparams(cipherparams);
        crypto.setCipher("aes-128-ctr");
        crypto.setKdf("scrypt");
    
        final WalletFile.ScryptKdfParams kdfparams = new WalletFile.ScryptKdfParams();
        kdfparams.setDklen(32);
        kdfparams.setSalt("e1a68d9bbb4991b1b067b049277cc279666d5b66b5b0f87dbe7fd62c9e2654f6");
        kdfparams.setN(8192);
        kdfparams.setR(8);
        kdfparams.setP(1);
        crypto.setKdfparams(kdfparams);
        crypto.setMac("e380dbb051072576140cbf1a97fd14d616cf8b012f0c7228ecfa966629664592");
        keystore.setCrypto(crypto);
    
        final String json = new Gson().toJson(keystore);
        final String privateKey = "290867651b60ccef677063030f06ad35037904124099b04deacb15de3bf12cca";
        final String password = "a123kkbox";
    
        // act
        final String result = Wallet.decrypt(password, keystore)
            .getPrivateKey()
            .toString(16);
    
        // assert
        assertThat(result)
            .isNotNull()
            .isEqualTo(privateKey);
      }
    }
    

https://github.com/ethereum/go-ethereum/issues/15407

https://github.com/matthiaszimmermann/ethereum-paper-wallet/blob/master/src/main/java/org/matthiaszimmermann/ethereum/pwg/PaperWallet.java

KeystoreFormat#fromKeystore() of ethereum-harmony is also the solution. It and web3j both use same crypto library - Spongy Castle.

https://github.com/ether-camp/ethereum-harmony/blob/develop/src/main/java/com/ethercamp/harmony/keystore/KeystoreFormat.java

Issue: Cost too long/OOM when n is huge

{
    "address":"0a3114dd29fc5ee0e9cc78109be1a425c2f34f47",
    "crypto":{
        "cipher":"aes-128-ctr",
        "ciphertext":"1cfad4b0d8d4b3ddee9ceb9bd02416a7aa029385839a86e79544243bf4c1468c",
        "cipherparams":{
            "iv":"3dfcf5dd030cb327034ba59c5e283af5"
        },
        "mac":"eadaafb8d49ee673b5ec18b1136eaca997c534115afc6bf9352b1b2a251c9d0d",
        "kdf":"scrypt",
        "kdfparams":{
            "dklen":32,
            "n":262144,
            "r":1,
            "p":8,
            "salt":"c5aec453aaec3ff3846ad9d9b2e307ee211a9989e5a1064ebcbbffa4401a8c7f"
        }
    },
    "id":"8e901909-6bd2-4a56-b09f-866dbcf7bfc6",
    "version":3
}

Using lambdaworks to instead of Spongy Castle crypto library.

https://lhalcyon.com/blockchain-eth-unlock-android/

results matching ""

    No results matching ""