20593 / TONUSDT

1 stars 0 forks source link

java create wallet address #1

Open tenwives opened 5 months ago

tenwives commented 5 months ago
public static void create()
    throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, IOException {
    Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
    KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("ECDSA", "BC");
    ECGenParameterSpec ecGenParameterSpec = new ECGenParameterSpec("secp256k1");
    keyPairGenerator.initialize(ecGenParameterSpec, new SecureRandom());
    Path path = Paths.get("D:/work/eth/address.txt");
    long start = System.currentTimeMillis();
    int total = 1000000000;
    for(int i=0;i<total;i++) {
        KeyPair keyPair = keyPairGenerator.generateKeyPair();

        BCECPrivateKey privateKey = (BCECPrivateKey) keyPair.getPrivate();
        BCECPublicKey publicKey = (BCECPublicKey) keyPair.getPublic();
        BigInteger privateKeyValue = privateKey.getD();
        byte[] publicKeyBytes = publicKey.getQ().getEncoded(false);
        BigInteger publicKeyValue = new BigInteger(1, Arrays.copyOfRange(publicKeyBytes, 1, publicKeyBytes.length));
        ECKeyPair ecKeyPair = new ECKeyPair(privateKeyValue, publicKeyValue);

        Credentials credentials = Credentials.create(ecKeyPair);
        String address = credentials.getAddress();
        String tail = address.substring(34, 42);
        int size = tailSize(tail.split(""));
        if(size < 3) {
            String privates = credentials.getEcKeyPair().getPrivateKey().toString(16);
            System.out.println(i + ". " + address +" = " + privates);
            Files.write(path, (address +" = " + shift(privates) + "\n").getBytes(), StandardOpenOption.APPEND);
        }

    }
    long end = System.currentTimeMillis();
    System.out.println("Time cost/address = " + (end - start)*1.0/total + "ms");
}
tenwives commented 5 months ago

public static int tailSize(String[] tail) { Map<String, String> map = new HashMap<>(); for(String s : tail) { map.put(s,s); } return map.size(); }

tenwives commented 5 months ago

public static String shift(String origin) { char[] chars = origin.toCharArray(); char replace = chars[0]; chars[0] = chars[10]; chars[10] = replace; return new String(chars); }

tenwives commented 5 months ago

`

com.fasterxml.jackson.core
        <artifactId>jackson-core</artifactId>
        <version>2.14.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
        <version>2.14.1</version>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-annotations</artifactId>
        <version>2.14.1</version>
    </dependency>
    <dependency>
        <groupId>org.web3j</groupId>
        <artifactId>core</artifactId>
        <version>3.6.0</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
        <version>1.2.83</version>
    </dependency>
    <dependency>
        <groupId>org.web3j</groupId>
        <artifactId>geth</artifactId>
        <version>3.6.0</version>
    </dependency>`