0

I am using web3j to create account.

String walletFileName = WalletUtils.generateFullNewWalletFile("
<password>",new File("some/path"));

But getting this error:

java.lang.ClassCastException: org.bouncycastle.jce.provider.JCEECPrivateKey cannot be cast to org.bouncycastle.jcajce.provider.asymmetric.ec.BCECPrivateKey

My setup in pom.xml is as follows:

<dependency>
    <groupId>org.web3j</groupId>
    <artifactId>core</artifactId>
    <version>3.4.0</version>
</dependency>
<dependency>
    <groupId>org.bouncycastle</groupId>
    <artifactId>bcprov-jdk15on</artifactId>
    <version>1.54</version>
</dependency>

Please let me know where I am going wrong.

1

Your code seem to be OK, I just created a project and I can run it:

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>io.gjeanmart.sandbox.web3j</groupId>
    <artifactId>Web3jCreateWallet</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.source>1.8</maven.compiler.source>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.web3j</groupId>
            <artifactId>core</artifactId>
            <version>3.4.0</version>
        </dependency>
    </dependencies>

</project>

PS: You don't really need to add bouncycastle as dependancy as it is pull by web3j:core directly.

enter image description here

TestCreateWallet.java

package io.gjeanmart.stackexchange.web3j.test;

import java.io.File;
import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;

import org.junit.Test;
import org.web3j.crypto.CipherException;
import org.web3j.crypto.WalletUtils;

public class TestCreateWallet {

    @Test
    public void createWallet() throws NoSuchAlgorithmException, NoSuchProviderException, InvalidAlgorithmParameterException, CipherException, IOException {

        String folder = "/tmp/wallet/";
        String password = "secr3t";

        File folderFile = new File(folder);
        folderFile.mkdirs();

        String walletFileName = WalletUtils.generateFullNewWalletFile(password, folderFile);
        System.out.println("Wallet generated: " + walletFileName);
    }

}

Result:

Wallet generated: UTC--2018-12-18T16-41-35.32000000Z--cdf77e5fbee401d12f394f4f47f883407e883bd1.json

Code:

Code available on Github

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.