Skip to content

Commit

Permalink
fix: edge case importing RSA key (#580)
Browse files Browse the repository at this point in the history
  • Loading branch information
OronDF343 committed Jun 28, 2024
1 parent a69164d commit 6436947
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions Vonage/PemParse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ THE SOFTWARE.
// Creates dummy unsigned certificate linked to private keypair and
// optionally exports to pkcs #12
//
// See also:
// http://www.openssl.org/docs/crypto/pem.html#PEM_ENCRYPTION_FORMAT
// See also:
// http://www.openssl.org/docs/crypto/pem.html#PEM_ENCRYPTION_FORMAT
//**************************************************************************************

using System;
Expand Down Expand Up @@ -177,6 +177,12 @@ public static RSA DecodeRSAPrivateKey(byte[] privkey, bool isPkcs8)
RSA = new RSACng();
}
#endif
if (D.Length < MODULUS.Length)
{
var newD = new byte[MODULUS.Length];
Array.Copy(D, 0, newD, MODULUS.Length - D.Length, D.Length);
D = newD;
}
var RSAparams = new RSAParameters
{
Modulus = MODULUS,
Expand Down Expand Up @@ -220,7 +226,7 @@ private static byte[] DecodeOpenSSLPrivateKey(string instr)
catch (FormatException)
{
//if can't b64 decode, it must be an encrypted private key
//Console.WriteLine("Not an unencrypted OpenSSL PEM private key");
//Console.WriteLine("Not an unencrypted OpenSSL PEM private key");
}

throw new NotSupportedException("Encrypted key not supported");
Expand Down

0 comments on commit 6436947

Please sign in to comment.