Skip to content

Commit

Permalink
RSACryptoServiceProvider missing function to initialize an instance o…
Browse files Browse the repository at this point in the history
…f the provider (#350)

<!-- Thank you for submitting a Pull Request. If you're new to
contributing to BCApps please read our pull request guideline below
* https://github.com/microsoft/BCApps/Contributing.md
-->
#### Summary <!-- Provide a general summary of your changes -->
A function is added to RSACryptoServiceProvider to initialize an
instance of the provider.

#### Work Item(s) <!-- Add the issue number here after the #. The issue
needs to be open and approved. Submitting PRs with no linked issues or
unapproved issues is highly discouraged. -->
Fixes #305 
<br /><br />Internal work item: AB#492550

---------

Co-authored-by: Alexander Holstrup <[email protected]>
  • Loading branch information
JaapMosselman and aholstrup1 authored Nov 28, 2023
1 parent b473afe commit 4011c27
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ codeunit 1445 "RSACryptoServiceProvider"
[NonDebuggable]
RSACryptoServiceProviderImpl: Codeunit "RSACryptoServiceProvider Impl.";

/// <summary>
/// Initializes a new instance of RSACryptoServiceProvider with the specified key size and returns the key as an XML string.
/// </summary>
/// <param name="KeySize">The size of the key in bits.</param>
procedure InitializeRSA(KeySize: Integer)
begin
RSACryptoServiceProviderImpl.InitializeRSA(KeySize);
end;

/// <summary>
/// Creates and returns an XML string containing the key of the current RSA object.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ codeunit 1446 "RSACryptoServiceProvider Impl." implements SignatureAlgorithm
var
DotNetRSACryptoServiceProvider: DotNet RSACryptoServiceProvider;

procedure InitializeRSA(KeySize: Integer)
begin
DotNetRSACryptoServiceProvider := DotNetRSACryptoServiceProvider.RSACryptoServiceProvider(KeySize);
end;

procedure GetInstance(var DotNetAsymmetricAlgorithm: DotNet AsymmetricAlgorithm)
begin
DotNetAsymmetricAlgorithm := DotNetRSACryptoServiceProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,24 @@ codeunit 132613 RSACryptoServiceProviderTests
IsInitialized := true;
end;

[Test]
procedure InitializeKeys()
var
KeyXml: XmlDocument;
Root: XmlElement;
Node: XmlNode;
KeyXmlText: Text;
begin
RSACryptoServiceProvider.InitializeRSA(2048);
KeyXmlText := RSACryptoServiceProvider.ToXmlString(true);

LibraryAssert.IsTrue(XmlDocument.ReadFrom(KeyXmlText, KeyXml), 'RSA key is not valid xml data.');
LibraryAssert.IsTrue(KeyXml.GetRoot(Root), 'Could not get Root element of key.');

LibraryAssert.IsTrue(Root.SelectSingleNode('Modulus', Node), 'Could not find <Modulus> in key.');
LibraryAssert.IsTrue(Root.SelectSingleNode('DQ', Node), 'Could not find <DQ> in key.');
end;

[Test]
procedure TestSignDataWithCert()
var
Expand Down

0 comments on commit 4011c27

Please sign in to comment.