pkcs1 vs X.509

X.509(SPKI):java语言定义的秘钥标准
X.509包含pkcs1
rsa-should-i-use-x-509-or-pkcs-

 // test data source
    KeyStore ks = KeyStore.getInstance("JKS"); 
    ks.load (new FileInputStream (args[0]), args[1].toCharArray());
    byte[] spkienc = ks.getCertificate(args[2]).getPublicKey().getEncoded();
    System.out.println(DatatypeConverter.printHexBinary(spkienc));

    // extract PKCS1 part of original SPKI
    byte[] pkcs1enc = SubjectPublicKeyInfo.getInstance(spkienc).parsePublicKey().getEncoded();
    System.out.println(DatatypeConverter.printHexBinary(pkcs1enc));

    // rebuild SPKI from the PKCS1
    AlgorithmIdentifier algid = new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE);
    byte[] spki2enc = new SubjectPublicKeyInfo(algid, pkcs1enc).getEncoded();
    System.out.println(DatatypeConverter.printHexBinary(spki2enc));
上一篇:C语言第三天


下一篇:元数据性能大比拼:HDFS vs OSS vs JuiceFS