From e5d2c79d050eb206302e5fc96da4543097769e16 Mon Sep 17 00:00:00 2001 From: marekvicar Date: Tue, 5 Dec 2023 12:48:14 +0100 Subject: [PATCH 1/2] New function suggestion in RSACryptoServiceProvider --- .../src/RSACryptoServiceProvider.Codeunit.al | 11 +++++++++++ .../RSACryptoServiceProviderImpl.Codeunit.al | 18 ++++++++++++++++++ .../App/DotNet Aliases/src/dotnet.al | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al index b16fa63ff3..a0e81dc893 100644 --- a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al +++ b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al @@ -81,4 +81,15 @@ codeunit 1445 "RSACryptoServiceProvider" begin RSACryptoServiceProviderImpl.Decrypt(XmlString, EncryptedTextInStream, OaepPadding, DecryptedTextOutStream); end; + + /// + /// Creates an instance of RSACryptoServiceProvider from the specified encrypted PKCS#8 private key. + /// + /// The input stream containig ecrypted PKCS#8 private key. + /// Password to decrypt the private key. + [NonDebuggable] + procedure ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream: InStream; Password: SecretText) + begin + RSACryptoServiceProviderImpl.ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream, Password); + end; } \ No newline at end of file diff --git a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al index 6f491898b6..a95f8691d8 100644 --- a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al +++ b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al @@ -142,6 +142,24 @@ codeunit 1446 "RSACryptoServiceProvider Impl." implements SignatureAlgorithm end; #endregion + #region Pkcs8 + [NonDebuggable] + procedure ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream: InStream; Password: SecretText) + var + EncryptedKeyBytes: DotNet Array; + PasswordChars: DotNet Array; + DotNetString: DotNet String; + ReadOnlySpan: DotNet ReadOnlySpan1; + BytesRead: Integer; + begin + InStreamToArray(EncryptedKeyInStream, EncryptedKeyBytes); + DotNetString := Password; + PasswordChars := DotNetString.ToCharArray(); + RSACryptoServiceProvider(); + DotNetRSACryptoServiceProvider.ImportEncryptedPkcs8PrivateKey(ReadOnlySpan.ReadOnlySpan(PasswordChars), ReadOnlySpan.ReadOnlySpan(EncryptedKeyBytes), BytesRead); + end; + #endregion + local procedure RSACryptoServiceProvider() begin DotNetRSACryptoServiceProvider := DotNetRSACryptoServiceProvider.RSACryptoServiceProvider(); diff --git a/src/System Application/App/DotNet Aliases/src/dotnet.al b/src/System Application/App/DotNet Aliases/src/dotnet.al index 1d546c13c9..830f148095 100644 --- a/src/System Application/App/DotNet Aliases/src/dotnet.al +++ b/src/System Application/App/DotNet Aliases/src/dotnet.al @@ -1466,6 +1466,10 @@ dotnet { } + type("System.ReadOnlySpan`1"; "ReadOnlySpan1") + { + } + type("System.Collections.ArrayList"; "ArrayList") { } From 1d1dc781c27ecb73e7961c2a5394a771bbd7f988 Mon Sep 17 00:00:00 2001 From: marekvicar Date: Tue, 5 Dec 2023 13:21:22 +0100 Subject: [PATCH 2/2] Password parameter as Text --- .../src/RSACryptoServiceProvider.Codeunit.al | 2 +- .../src/RSACryptoServiceProviderImpl.Codeunit.al | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al index a0e81dc893..832eb26cb3 100644 --- a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al +++ b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProvider.Codeunit.al @@ -88,7 +88,7 @@ codeunit 1445 "RSACryptoServiceProvider" /// The input stream containig ecrypted PKCS#8 private key. /// Password to decrypt the private key. [NonDebuggable] - procedure ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream: InStream; Password: SecretText) + procedure ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream: InStream; Password: Text) begin RSACryptoServiceProviderImpl.ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream, Password); end; diff --git a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al index a95f8691d8..5aaacb6a71 100644 --- a/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al +++ b/src/System Application/App/Cryptography Management/src/RSACryptoServiceProviderImpl.Codeunit.al @@ -144,7 +144,7 @@ codeunit 1446 "RSACryptoServiceProvider Impl." implements SignatureAlgorithm #region Pkcs8 [NonDebuggable] - procedure ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream: InStream; Password: SecretText) + procedure ImportEncryptedPkcs8PrivateKey(EncryptedKeyInStream: InStream; Password: Text) var EncryptedKeyBytes: DotNet Array; PasswordChars: DotNet Array;