RSA,PKCS#1,PKCS#8
openssl genrsa -out rsa_private_key.pem
openssl rsa -in rsa_private_key.pem -text -noout -out rsa_private_key.txt
openssl pkcs8 -in rsa_private_key.pem -topk8 -v2 aes-256-cbc -out rsa_enc_private_key.pem
openssl pkcs8 -in rsa_private_key.pem -topk8 -v2 aes-256-cbc -v2prf hmacWithSHA256 -out rsa_enc_private_key.pem
test("rsa private key", () {
//openssl genrsa -out rsa_private_key.pem
File rsa_private_key_file = new File("./resource/rsa_private_key.pem");
String pem = rsa_private_key_file.readAsStringSync();
RSAPKCSParser parser = new RSAPKCSParser();
RSAKeyPair pair = parser.parsePEM(pem);
var privateKey = pair.private;
expect(pair.public , equals(null));
expect(privateKey != null , equals(true));
expect(privateKey.version, equals(0));
expect(privateKey.modulus , equals(new BigInteger ([0x00,0xd8,0x3c,0x3c,0xac,0xb3,0xb7,0x67,0xa1,0x02,0x0f,0x94,0x7c,0xa2,0x01,0x20,0x10,0xba,0x49,0x4d,0x86,0xbd,0xa1,0xef,0xd4,0x37,0x35,0x7b,0x91,0xd5,0xc1,0xe6,0x1b,0x12,0x38,0x4c,0xd3,0xc0,0x1f,0x62,0x83,0x12,0xa5,0xef,0x15,0xcf,0x00,0x3f,0x62,0xc4,0xf6,0xb8,0x35,0xbb,0xb3,0xea,0x99,0x40,0x9f,0x87,0xe5,0x83,0xfa,0x69,0x91])));
expect(privateKey.publicExponent, equals(65537));
expect(privateKey.privateExponent , equals(new BigInteger ([0x00,0xa0,0xc2,0x2f,0xcd,0xa9,0x92,0xb9,0xcd,0x5e,0xed,0xdc,0x53,0xc8,0x51,0x93,0xd8,0x3b,0xd6,0x91,0x77,0x91,0xf6,0x19,0x8a,0x29,0x3d,0x6e,0xcf,0xde,0x1e,0x58,0x85,0xfb,0xc0,0xa7,0x66,0xaa,0xca,0x38,0x5d,0xd8,0xb3,0xb1,0x6a,0x58,0x20,0x1b,0xae,0xc3,0x90,0x0b,0x5c,0x16,0x36,0x32,0x1a,0x01,0x67,0xe9,0x56,0xd5,0xfb,0xe0,0x01])));
expect(privateKey.prime1 , equals(new BigInteger ([0x00,0xf3,0x10,0x3a,0x1b,0xb1,0x4f,0x88,0xf0,0x96,0x98,0x3e,0xcd,0x86,0xcb,0x51,0xf9,0xe0,0xe9,0x32,0x50,0x30,0x03,0x9b,0xe4,0xfb,0xb4,0x17,0x6d,0xe1,0xb7,0x3f,0x91])));
expect(privateKey.prime2 , equals(new BigInteger ([0x00,0xe3,0xbe,0x79,0x3b,0x59,0x3e,0x4e,0xd5,0xbc,0xe5,0xdb,0x1f,0xf5,0x63,0x46,0x8e,0xeb,0x5c,0xc7,0x15,0xb1,0x2b,0xad,0xf2,0x23,0xd1,0x97,0x0c,0xd8,0x8f,0x8a,0x01])));
expect(privateKey.exponent1 , equals(new BigInteger ([0x7e,0x4e,0x88,0x63,0xab,0x98,0x31,0x09,0x14,0xb8,0xb8,0xaa,0x04,0xc9,0xd3,0x27,0x8e,0x80,0x9f,0xec,0x9b,0x86,0xc4,0x94,0x11,0x58,0x5c,0x74,0x75,0x3e,0xcc,0x81])));
expect(privateKey.exponent2, equals(new BigInteger ([0x68,0x7f,0x82,0x72,0xf7,0xec,0xfe,0x11,0x56,0x9e,0x85,0x5f,0xf1,0xa1,0x7e,0xc3,0x9f,0x3d,0x2f,0xe0,0x45,0x2e,0x0c,0x9f,0x79,0x4d,0xf7,0x28,0x1e,0xca,0x26,0x01])));
expect(privateKey.coefficient , equals(new BigInteger ([0x00,0x92,0xe8,0x95,0xc1,0xa9,0xb7,0xb7,0x05,0xfb,0x69,0x4b,0xba,0x2d,0x52,0xcb,0x99,0x01,0xd4,0x62,0x8d,0xb7,0x94,0xeb,0x43,0x86,0x1b,0x08,0x6c,0x55,0x7d,0x29,0x13])));
});
test("rsa public key", () {
//openssl genrsa -out rsa_private_key.pem
//openssl rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
File rsa_private_key_file = new File("./resource/rsa_public_key.pem");
String pem = rsa_private_key_file.readAsStringSync();
RSAPKCSParser parser = new RSAPKCSParser();
RSAKeyPair pair = parser.parsePEM(pem);
var privateKey = pair.private;
var publicKey = pair.public;
expect(privateKey , equals(null));
expect(publicKey != null , equals(true));
expect(publicKey.modulus , equals(new BigInteger ([0x00,0xd8,0x3c,0x3c,0xac,0xb3,0xb7,0x67,0xa1,0x02,0x0f,0x94,0x7c,0xa2,0x01,0x20,0x10,0xba,0x49,0x4d,0x86,0xbd,0xa1,0xef,0xd4,0x37,0x35,0x7b,0x91,0xd5,0xc1,0xe6,0x1b,0x12,0x38,0x4c,0xd3,0xc0,0x1f,0x62,0x83,0x12,0xa5,0xef,0x15,0xcf,0x00,0x3f,0x62,0xc4,0xf6,0xb8,0x35,0xbb,0xb3,0xea,0x99,0x40,0x9f,0x87,0xe5,0x83,0xfa,0x69,0x91])));
expect(publicKey.publicExponent, equals(65537));
});