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

将ECKeyPair中的PrivateKey保存为.pem文件的方法 #344

Open
hello-zxx opened this issue Jul 12, 2019 · 0 comments
Open

将ECKeyPair中的PrivateKey保存为.pem文件的方法 #344

hello-zxx opened this issue Jul 12, 2019 · 0 comments
Assignees

Comments

@hello-zxx
Copy link

是否没有提供将PrivateKey保存的.pem的方法?

目前通过如下方法将PrivateKey保存为.pem

public void savePrivateKey(OutputStream outputStream, BigInteger privateKey) throws Exception{
        ECNamedCurveParameterSpec ecNamedCurveParameterSpec = ECNamedCurveTable.getParameterSpec("secp256k1");
        ECPrivateKeySpec ecPrivateKeySpec = new ECPrivateKeySpec(privateKey,ecNamedCurveParameterSpec);
        KeyFactory keyFactory = KeyFactory.getInstance("ECDSA");
        keyFactory.generatePrivate(ecPrivateKeySpec).getEncoded();
        outputStream.write(
                ("-----BEGIN PRIVATE KEY-----\n" +
                        Base64.encodeBase64String(keyFactory.generatePrivate(ecPrivateKeySpec).getEncoded()) +
                 "\n-----END PRIVATE KEY-----\n").getBytes()
        );
        outputStream.close();
    }

是否有其他内置方法可供调用?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants