Skip to content

Commit

Permalink
Merge pull request #1059 from GekySan/master
Browse files Browse the repository at this point in the history
Add elliptic curve support for JWT signature
  • Loading branch information
openbullet authored Jul 11, 2024
2 parents de53ca9 + edefa6f commit 4b2a9bb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions RuriLib/Functions/Crypto/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ public static string JwtEncode(JwtAlgorithmName algorithmName, string secret, ID
{
IJwtAlgorithm algorithm = null;
RSA rsa = null;
ECDsa ecdsa = null;
try
{
switch (algorithmName)
Expand Down Expand Up @@ -671,6 +672,21 @@ public static string JwtEncode(JwtAlgorithmName algorithmName, string secret, ID
rsa.ImportFromPem(secret.ToCharArray());
algorithm = new RS4096Algorithm(rsa, rsa);
break;
case JwtAlgorithmName.ES256:
ecdsa = ECDsa.Create();
ecdsa.ImportFromPem(secret.ToCharArray());
algorithm = new ES256Algorithm(ecdsa, ecdsa);
break;
case JwtAlgorithmName.ES384:
ecdsa = ECDsa.Create();
ecdsa.ImportFromPem(secret.ToCharArray());
algorithm = new ES384Algorithm(ecdsa, ecdsa);
break;
case JwtAlgorithmName.ES512:
ecdsa = ECDsa.Create();
ecdsa.ImportFromPem(secret.ToCharArray());
algorithm = new ES512Algorithm(ecdsa, ecdsa);
break;
default:
throw new NotSupportedException("This algorithm is not supported at the moment");
}
Expand All @@ -684,6 +700,7 @@ public static string JwtEncode(JwtAlgorithmName algorithmName, string secret, ID
finally
{
rsa?.Dispose();
ecdsa?.Dispose();
}
}
#endregion
Expand Down

0 comments on commit 4b2a9bb

Please sign in to comment.