I have a private key
-----BEGIN PRIVATE KEY-----
MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDYBVtUvXXQZaK1
7NsTC6yLahsAAkrejbEvNdjA1AW1PPOhj3m2UM7cmI7cLODrV7UY5UpEGL7UWUQi
...
-----END PRIVATE KEY-----
and running openssl rsa -in privkey.txt -text -noout
on it provides me with all the necessary info about it:
Private-Key: (2048 bit)
modulus:
00:d8:05:5b:54:bd:75:d0:65:a2:b5:ec:db:13:0b:
ac:8b:6a:1b:00:02:4a:de:8d:b1:2f:35:d8:c0:d4:
...
publicExponent: 65537 (0x10001)
privateExponent:
14:3d:c0:41:3a:f5:78:9e:fa:b5:90:3e:e0:d4:7b:
08:f4:85:6e:25:48:d8:52:04:df:0c:6d:1b:23:0d:
71:33:87:b7:ef:91:33:2f:9e:df:d5:b3:01:2c:d0:
05:cd:49:ec:a3:6e:27:88:fd:61:e4:06:b9:d4:f6:
...
But it doesn’t quite work with elixir
iex(1)> {:ok, privkey} = File.read("privkey.txt")
{:ok, "-----BEGIN PRIVATE KEY-----\nMIIE ..."}
iex(3)> [private_key_info] = :public_key.pem_decode(privkey)
[{:PrivateKeyInfo,
<<48, 130, 4, 190, 2, 1, 0, 48, 13, 6, 9, 42, 134, 72, 134, 247, 13, 1, 1, 1,
5, 0, 4, 130, 4, 168, 48, 130, 4, 164, 2, 1, 0, 2, 130, 1, 1, 0, 216, 5, 91,
84, 189, 117, 208, 101, 162, 181, ...>>, :not_encrypted}]
iex(5)> key = :public_key.pem_entry_decode(private_key_info)
{:PrivateKeyInfo, :v1,
{:PrivateKeyInfo_privateKeyAlgorithm, {1, 2, 840, 113549, 1, 1, 1},
{:asn1_OPENTYPE, <<5, 0>>}},
<<48, 130, 4, 164, 2, 1, 0, 2, 130, 1, 1, 0, 216, 5, 91, 84, 189, 117, 208,
101, 162, 181, 236, 219, 19, 11, 172, 139, 106, 27, 0, 2, 74, 222, 141, 177,
47, 53, 216, 192, 212, 5, 181, 60, 243, 161, ...>>, :asn1_NOVALUE}
I would expect to get a #RSAPrivateKey{}
record.
It does work with a key starting with -----BEGIN RSA PRIVATE KEY-----
.
Is there a way to specify that the private key is RSA?