java - How to convert Byte array to PrivateKey or PublicKey type? -
i using rsa algorithm generate public , private key
final keypairgenerator keygen = keypairgenerator.getinstance(algorithm); keygen.initialize(1024); final keypair key = keygen.generatekeypair(); final privatekey privatekey=key.getprivate(); final publickey publickey=key.getpublic();
after these keys encoded using base64 encoder , save database.
how convert encoded string private , public key type in java decrypt file. when decoding string using base64decoder byte array. how convert byte array public or private key type?
if have byte[] representing output of getencoded() on key, can use keyfactory turn publickey object or privatekey object.
byte[] privatekeybytes; byte[] publickeybytes; keyfactory kf = keyfactory.getinstance("rsa"); // or "ec" or whatever privatekey privatekey = kf.generateprivate(new pkcs8encodedkeyspec(privatekeybytes)); publickey publickey = kf.generatepublic(new x509encodedkeyspec(publickeybytes));
Comments
Post a Comment