美文网首页
Read RSA Private Key Java: algid

Read RSA Private Key Java: algid

作者: icebinger | 来源:发表于2021-09-02 13:10 被阅读0次

# 1

···

        KeyFactory keyFactory = KeyFactory.getInstance("RSA");

        byte[] encodeByte = Base64.getDecoder().decode(privateKeyString);

        RSAPrivateKey privateKey = (RSAPrivateKey) keyFactory.generatePrivate(parsePKCS1( encodeByte ) );

        Algorithm algorithm = Algorithm.RSA256(null, privateKey );

···


``` 

private static RSAPrivateCrtKeySpecparsePKCS1(byte[] source) {

Asn1Parser p =new Asn1Parser(source);

    // https://en.wikipedia.org/wiki/X.690#BER_encoding

// https://tools.ietf.org/html/rfc8017#page-55

// Type (sequence)

    p.parseTag(0x30);

    // Length

    p.parseFullLength();

    BigInteger version = p.parseInt();

    if (version.intValue() ==1) {

// JRE doesn't provide a suitable constructor for multi-prime

// keys

        log.error("parse error" );

    }

return new RSAPrivateCrtKeySpec(p.parseInt(), p.parseInt(), p.parseInt(), p.parseInt(),

            p.parseInt(), p.parseInt(), p.parseInt(), p.parseInt());

}

``` 

相关文章

网友评论

      本文标题:Read RSA Private Key Java: algid

      本文链接:https://www.haomeiwen.com/subject/ovmqwltx.html