summary refs log tree commit diff
path: root/crypto/src/crmf/PKMacValueGenerator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/crmf/PKMacValueGenerator.cs')
-rw-r--r--crypto/src/crmf/PKMacValueGenerator.cs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crypto/src/crmf/PKMacValueGenerator.cs b/crypto/src/crmf/PKMacValueGenerator.cs
new file mode 100644
index 000000000..0809de348
--- /dev/null
+++ b/crypto/src/crmf/PKMacValueGenerator.cs
@@ -0,0 +1,28 @@
+using System;
+
+using Org.BouncyCastle.Asn1.Crmf;
+using Org.BouncyCastle.Asn1.X509;
+using Org.BouncyCastle.X509;
+
+namespace Org.BouncyCastle.Crmf
+{
+    internal static class PKMacValueGenerator
+    {
+#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
+        internal static PKMacValue Generate(PKMacBuilder builder, ReadOnlySpan<char> password,
+            SubjectPublicKeyInfo keyInfo)
+        {
+            var macFactory = builder.Build(password);
+            var macValue = X509Utilities.GenerateMac(macFactory, keyInfo);
+            return new PKMacValue((AlgorithmIdentifier)macFactory.AlgorithmDetails, macValue);
+        }
+#else
+        internal static PKMacValue Generate(PKMacBuilder builder, char[] password, SubjectPublicKeyInfo keyInfo)
+        {
+            var macFactory = builder.Build(password);
+            var macValue = X509Utilities.GenerateMac(macFactory, keyInfo);
+            return new PKMacValue((AlgorithmIdentifier)macFactory.AlgorithmDetails, macValue);
+        }
+#endif
+    }
+}