-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Init RSA PSS SignatureAlgorithm Implementation (#867)
#### Summary As far as I know, the existing RSACryptoServiceProvider implementation does not offer the option of specifying the PSS padding. My online research has also shown that this is not possible either. Therefore, I would like to add my own implementation of the "SignatureAlgorithm" interface based on the "System.Security.Cryptography.RSA" class. For my use case, only a function that signs the data is sufficient. However, I think that the interface implementation is more similar to the styleguid. #### Work Item(s) Fixes #866 Fixes [AB#524188](https://dynamicssmb2.visualstudio.com/1fcb79e7-ab07-432a-a3c6-6cf5a88ba4a5/_workitems/edit/524188)
- Loading branch information
Showing
9 changed files
with
674 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,7 +85,7 @@ | |
}, | ||
{ | ||
"from": 1473, | ||
"to": 1474 | ||
"to": 1476 | ||
} | ||
], | ||
"target": "OnPrem", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
src/System Application/App/Cryptography Management/src/RSA.Codeunit.al
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// ------------------------------------------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See License.txt in the project root for license information. | ||
// ------------------------------------------------------------------------------------------------ | ||
|
||
namespace System.Security.Encryption; | ||
|
||
/// <summary> | ||
/// Performs asymmetric encryption and digital signature using the implementation of the RSA class. | ||
/// </summary> | ||
codeunit 1475 "RSA" | ||
{ | ||
Access = Public; | ||
InherentEntitlements = X; | ||
InherentPermissions = X; | ||
|
||
var | ||
RSAImpl: Codeunit "RSA Impl."; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of RSA with the specified key size. | ||
/// </summary> | ||
/// <param name="KeySize">The size of the key in bits.</param> | ||
procedure InitializeRSA(KeySize: Integer) | ||
begin | ||
RSAImpl.InitializeRSA(KeySize); | ||
end; | ||
|
||
/// <summary> | ||
/// Creates and returns an XML string containing the key of the current RSA object. | ||
/// </summary> | ||
/// <param name="IncludePrivateParameters">true to include a public and private RSA key; false to include only the public key.</param> | ||
/// <returns>An XML string containing the key of the current RSA object.</returns> | ||
procedure ToSecretXmlString(IncludePrivateParameters: Boolean): SecretText | ||
begin | ||
exit(RSAImpl.ToSecretXmlString(IncludePrivateParameters)); | ||
end; | ||
|
||
/// <summary> | ||
/// Computes the hash value of the specified data and signs it. | ||
/// </summary> | ||
/// <param name="XmlString">The XML string containing RSA key information.</param> | ||
/// <param name="DataInStream">The input stream to hash and sign.</param> | ||
/// <param name="HashAlgorithm">The hash algorithm to use to create the hash value.</param> | ||
/// <param name="RSASignaturePadding">The padding mode to use for the RSA signature.</param> | ||
/// <param name="SignatureOutStream">The RSA signature stream for the specified data.</param> | ||
procedure SignData(XmlString: SecretText; DataInStream: InStream; HashAlgorithm: Enum "Hash Algorithm"; RSASignaturePadding: Enum "RSA Signature Padding"; SignatureOutStream: OutStream) | ||
begin | ||
RSAImpl.SignData(XmlString, DataInStream, HashAlgorithm, RSASignaturePadding, SignatureOutStream); | ||
end; | ||
|
||
/// <summary> | ||
/// Verifies that a digital signature is valid by determining the hash value in the signature using the provided public key and comparing it to the hash value of the provided data. | ||
/// </summary> | ||
/// <param name="XmlString">The XML string containing RSA key information.</param> | ||
/// <param name="DataInStream">The input stream of data that was signed.</param> | ||
/// <param name="HashAlgorithm">The name of the hash algorithm used to create the hash value of the data.</param> | ||
/// <param name="RSASignaturePadding">The padding mode to use for the RSA signature.</param> | ||
/// <param name="SignatureInStream">The stream of signature data to be verified.</param> | ||
/// <returns>True if the signature is valid; otherwise, false.</returns> | ||
procedure VerifyData(XmlString: SecretText; DataInStream: InStream; HashAlgorithm: Enum "Hash Algorithm"; RSASignaturePadding: Enum "RSA Signature Padding"; SignatureInStream: InStream): Boolean | ||
begin | ||
exit(RSAImpl.VerifyData(XmlString, DataInStream, HashAlgorithm, RSASignaturePadding, SignatureInStream)); | ||
end; | ||
|
||
/// <summary> | ||
/// Encrypts the specified text with the RSA algorithm. | ||
/// </summary> | ||
/// <param name="XmlString">The XML string containing RSA key information.</param> | ||
/// <param name="PlainTextInStream">The input stream to encrypt.</param> | ||
/// <param name="OaepPadding">True to perform RSA encryption using OAEP padding; otherwise, false to use PKCS#1 padding.</param> | ||
/// <param name="EncryptedTextOutStream">The RSA encryption stream for the specified text.</param> | ||
procedure Encrypt(XmlString: SecretText; PlainTextInStream: InStream; OaepPadding: Boolean; EncryptedTextOutStream: OutStream) | ||
begin | ||
RSAImpl.Encrypt(XmlString, PlainTextInStream, OaepPadding, EncryptedTextOutStream); | ||
end; | ||
|
||
/// <summary> | ||
/// Decrypts the specified text that was previously encrypted with the RSA algorithm. | ||
/// </summary> | ||
/// <param name="XmlString">The XML string containing RSA key information.</param> | ||
/// <param name="EncryptedTextInStream">The input stream to decrypt.</param> | ||
/// <param name="OaepPadding">true to perform RSA encryption using OAEP padding; otherwise, false to use PKCS#1 padding.</param> | ||
/// <param name="DecryptedTextOutStream">The RSA decryption stream for the specified text.</param> | ||
procedure Decrypt(XmlString: SecretText; EncryptedTextInStream: InStream; OaepPadding: Boolean; DecryptedTextOutStream: OutStream) | ||
begin | ||
RSAImpl.Decrypt(XmlString, EncryptedTextInStream, OaepPadding, DecryptedTextOutStream); | ||
end; | ||
} |
Oops, something went wrong.