Coder Social home page Coder Social logo

Moving EC Keys Into BouncyCastle about jsrsasign HOT 3 CLOSED

kjur avatar kjur commented on May 22, 2024 1
Moving EC Keys Into BouncyCastle

from jsrsasign.

Comments (3)

Ruffio avatar Ruffio commented on May 22, 2024

@BlueMeanie has this 'issue' been resolved? It looks like it was a question about implementation and not a bug/issue. Please consider to close it. Thanks.

from jsrsasign.

Ruffio avatar Ruffio commented on May 22, 2024

@kjur this question should be closed due to lack of response from originator

from jsrsasign.

kjur avatar kjur commented on May 22, 2024

To share key between Java and jsrsasign, I would recommend to share them in PKCS#8 DER private and public key format.

For example "prv.p8p.der" is a PKCS#8 DER formatted binary plain EC private key file and
"pub.p8.der" is a PKCS#8 DER formatted binary EC public key file.

Then to load private key in Java:

byte[] prvKeyBytes = loadBytes("../prv.p8p.der");
KeyFactory kf = KeyFactory.getInstance("EC");
KeySpec keySpec = new PKCS8EncodedKeySpec(prvKeyBytes);
PrivateKey prvKey = kf.generatePrivate(keySpec);

To load public key in Java:

byte[] pubKeyBytes = loadBytes("../pub.p8.der");
KeyFactory kf = KeyFactory.getInstance("EC");
KeySpec keySpec = new X509EncodedKeySpec(certBytes);
PublicKey pubKey = kf.generatePublic(keySpec);

To load private key in JavaScript with jsrsasign:

rs = require("jsrsasign");
rsu = require("jsrsasign-util");
hPrv = rsu.readFileHexBin("prv.p8p.der");
prvkey = rs.KEYUTIL.getKey(hPrv, "pkcs8rv");

To load public key in JavaScript with jsrsasign:

rs = require("jsrsasign");
rsu = require("jsrsasign-util");
hPub = rsu.readFileHexBin("pub.p8.der");
pubkey = rs.KEYUTIL.getKey(hPub, "pkcs8pub");

from jsrsasign.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.