Skip to content

Commit

Permalink
unit tests updates, renamed RsaOaep256Management -> RsaOaepManagement
Browse files Browse the repository at this point in the history
  • Loading branch information
dvsekhvalnov committed Oct 30, 2024
1 parent 6d652fa commit a39777a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
18 changes: 17 additions & 1 deletion UnitTestsNet46/TestSuite.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,21 @@ public void Decrypt_RSA_OAEP_256_A256CBC_HS512()
Assert.Equal(@"{""exp"":1392553211,""sub"":""alice"",""nbf"":1392552611,""aud"":[""https:\/\/app-one.com"",""https:\/\/app-two.com""],""iss"":""https:\/\/openid.net"",""jti"":""586dd129-a29f-49c8-9de7-454af1155e27"",""iat"":1392552611}", json);
}

[Fact]
public void Decrypt_RSA_OAEP_256_A128GCM()
{
//given
const string token = "eyJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAtMjU2In0.Ki1uPWs34nXxE2nGmie94nGkcl1KbJcutGIRL2x7025JXITQ905nGlMqPf4YjgzvJxj51oc0EARPfC6IrFVlefuJzeKbJgZNj0IBkIKL1UbxkP0PrCovuXOnQhfYbcbppC0uNA6SDdGUiCJZH9DNnEBjQcbUWmDAdLSmI0ZkBhYK7fsla7dITP6rcAPM8wQcN6JqcVFZ-s_-uP8B6o2ywkawdtTacsQq9UxJvJ5bKfXJSNT-0xZY5kevgUo7rbJIpzv6BpFsA4EduOVMGu9Y7Xu_4seNIHZQA4NEqTxtbwjuq1lUdkm6Bnkr7GSXJ8tRjoFRf6OD2aX-snFx6Zg-MA.ez2XiQxsD1dvkehk._UCAGhvkeUWHKNa5lHQZvPpvWyH7j4E6wPJFLeNIFe53WCWVBVqFPoBRa5SANLak2COOgF__KBezLp935hROEvmtgFqJ5adl9uF501fCN0Cq-53bZP5MjKP237fOcZYQrGcei2GRRG-vOMt--owVX0Wjyy4Jy0oLqf9-hHoImtyLTpM89nN1s3jKcpsMntIfiqespShHLehZ0zW4v9pzT0ScHmSdjSqsisqcA0Za71GzPRoNIq5BzCvIf0TR6Q.hm0FdUsB0iHd1yrJW4Omzg";

//when
string json = Jose.JWT.Decode(token, RsaKey.New(PrivKey().ExportParameters(true)));

//then
Console.Out.WriteLine("json = {0}", json);

Assert.Equal(@"{""sub"":""alice"",""aud"":[""https://app-one.com"",""https://app-two.com""],""nbf"":1730312729,""iss"":""https://openid.net"",""exp"":1730313329,""iat"":1730312729,""jti"":""d8915fdb-8985-4c86-ae8d-28567016f623""}", json);
}

[Fact]
public void Decrypt_RSA_OAEP_384_A192GCM()
{
Expand Down Expand Up @@ -1182,7 +1197,8 @@ public void Encrypt_RSA_OAEP_512_A256GCM()
const string json = @"{""hello"": ""world""}";

//when
string token = Jose.JWT.Encode(json, RsaKey.New(PubKey().ExportParameters(false)), JweAlgorithm.RSA_OAEP_512, JweEncryption.A256GCM);
Jwk publicKey = new Jwk("AQAB", "qFZv0pea_jn5Mo4qEUmStuhlulso8n1inXbEotd_zTrQp9K0RK0hf7t0K4BjKVhaiqIam4tVVQvkmYeBeYr1MmnO_0N97dMBz_7fmvyv0hgHaBdQ5mR5u3LTlHo8tjRE7-GzZmGs6jMcyj7HbXobDPQJZpqNy6JjliDVXxW8nWJDetxGBlqmTj1E1fr2RCsZLreDOPSDIedG1upz9RraShsIDzeefOcKibcAaKeeVI3rkAU8_mOauLSXv37hlk0h6sStJb3qZQXyOUkVkjXIkhvNu_ve0v7LiLT4G_OxYGzpOQcCnimKdojzNP6GtVDaMPh-QkSJE32UCos9R3wI2Q");
string token = Jose.JWT.Encode(json, publicKey, JweAlgorithm.RSA_OAEP_512, JweEncryption.A256GCM);

//then
Console.Out.WriteLine("RSA_OAEP_512_A256GCM={0}", token);
Expand Down
6 changes: 3 additions & 3 deletions jose-jwt/JWTSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,9 @@ public JwtSettings()
private readonly Dictionary<JweAlgorithm, IKeyManagement> keyAlgorithms = new Dictionary<JweAlgorithm, IKeyManagement>
{
{ JweAlgorithm.RSA_OAEP, new RsaKeyManagement(true) },
{ JweAlgorithm.RSA_OAEP_256, new RsaOaep256KeyManagement(256) },
{ JweAlgorithm.RSA_OAEP_384, new RsaOaep256KeyManagement(384) },
{ JweAlgorithm.RSA_OAEP_512, new RsaOaep256KeyManagement(512) },
{ JweAlgorithm.RSA_OAEP_256, new RsaOaepKeyManagement(256) },
{ JweAlgorithm.RSA_OAEP_384, new RsaOaepKeyManagement(384) },
{ JweAlgorithm.RSA_OAEP_512, new RsaOaepKeyManagement(512) },
{ JweAlgorithm.RSA1_5, new RsaKeyManagement(false) },
{ JweAlgorithm.DIR, new DirectKeyManagement() },
{ JweAlgorithm.A128KW, new AesKeyWrapManagement(128) },
Expand Down
2 changes: 1 addition & 1 deletion jose-jwt/jose-jwt.net47.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Compile Include="jwa\IKeyManagement.cs" />
<Compile Include="jwa\Pbse2HmacShaKeyManagementWithAesKeyWrap.cs" />
<Compile Include="jwa\RsaKeyManagement.cs" />
<Compile Include="jwa\RsaOaep256KeyManagement.cs" />
<Compile Include="jwa\RsaOaepKeyManagement.cs" />
<Compile Include="jwe\AesCbcHmacEncryption.cs" />
<Compile Include="jwe\AesGcmEncryption.cs" />
<Compile Include="jwe\IJweAlgorithm.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

namespace Jose
{
public class RsaOaep256KeyManagement : IKeyManagement
public class RsaOaepKeyManagement : IKeyManagement
{
private readonly int hashSizeBits;

public RsaOaep256KeyManagement(int hashSizeBits)
public RsaOaepKeyManagement(int hashSizeBits)
{
this.hashSizeBits = hashSizeBits;
}
Expand Down

0 comments on commit a39777a

Please sign in to comment.