Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expected to get a 64-bit private key, but actually got 63 bits #2135

Open
bai-xuan opened this issue Dec 27, 2024 · 0 comments
Open

Expected to get a 64-bit private key, but actually got 63 bits #2135

bai-xuan opened this issue Dec 27, 2024 · 0 comments
Labels
bug A bug in behaviour or functionality

Comments

@bai-xuan
Copy link

Bug_title

A clear and concise description of what the issue is.
Expected to get a 64-bit private key, but actually got 63 bits

Steps To Reproduce

Describe the exact steps or scenario to reproduce the issue.
`
import org.web3j.crypto.Bip32ECKeyPair;
import org.web3j.crypto.Credentials;
import org.web3j.crypto.MnemonicUtils;

import java.security.SecureRandom;

public static void main(String[] args) {
SecureRandom secureRandom = new SecureRandom();

    while (true) {
        byte[] initialEntropy = new byte[16];
        secureRandom.nextBytes(initialEntropy);
        String mnemonic = MnemonicUtils.generateMnemonic(initialEntropy);
        String password = "";
        byte[] seed = MnemonicUtils.generateSeed(mnemonic, password);
        Bip32ECKeyPair bip32ECKeyPair = Bip32ECKeyPair.generateKeyPair(seed);
        Credentials credentials = Credentials.create(bip32ECKeyPair);
        String privateKeyStr = credentials.getEcKeyPair().getPrivateKey().toString(16);
        String address = credentials.getAddress();
        if (privateKeyStr.length() != 64) {
            System.out.println("The private key length is incorrect");
            System.out.println("address: " + address);
            System.out.println("privateKeyStr: " + privateKeyStr);
            System.out.println("privateKeyStr length: " + privateKeyStr.length());
            System.out.println("mnemonic: " + mnemonic);
            break;
        }
    }
}`

Expected behavior

A clear and concise description of what you expected to happen.

Expected to get a 64-bit private key, but actually got 63 bits

Environment

Describe the environment in which the issue occurs

  • Web3j version :4.12.3
  • Java or Android version :openjdk-17.0.11+9
  • Operating System :win11

image

@bai-xuan bai-xuan added the bug A bug in behaviour or functionality label Dec 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug in behaviour or functionality
Projects
None yet
Development

No branches or pull requests

1 participant