summary refs log tree commit diff
path: root/crypto/src/tls/TlsRsaUtilities.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/src/tls/TlsRsaUtilities.cs')
-rw-r--r--crypto/src/tls/TlsRsaUtilities.cs24
1 files changed, 24 insertions, 0 deletions
diff --git a/crypto/src/tls/TlsRsaUtilities.cs b/crypto/src/tls/TlsRsaUtilities.cs
new file mode 100644
index 000000000..d520d3ea2
--- /dev/null
+++ b/crypto/src/tls/TlsRsaUtilities.cs
@@ -0,0 +1,24 @@
+using System;
+using System.IO;
+
+using Org.BouncyCastle.Tls.Crypto;
+
+namespace Org.BouncyCastle.Tls
+{
+    /// <summary>RSA Utility methods.</summary>
+    public abstract class TlsRsaUtilities
+    {
+        /// <summary>Generate a pre_master_secret and send it encrypted to the server.</summary>
+        /// <exception cref="IOException"/>
+        public static TlsSecret GenerateEncryptedPreMasterSecret(TlsContext context, TlsCertificate certificate,
+            Stream output)
+        {
+            TlsSecret preMasterSecret = context.Crypto.GenerateRsaPreMasterSecret(context.RsaPreMasterSecretVersion);
+
+            byte[] encryptedPreMasterSecret = preMasterSecret.Encrypt(certificate);
+            TlsUtilities.WriteEncryptedPms(context, encryptedPreMasterSecret, output);
+
+            return preMasterSecret;
+        }
+    }
+}