summary refs log tree commit diff
path: root/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/test/src/asn1/test/PrivateKeyInfoTest.cs')
-rw-r--r--crypto/test/src/asn1/test/PrivateKeyInfoTest.cs60
1 files changed, 60 insertions, 0 deletions
diff --git a/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs b/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs
new file mode 100644
index 000000000..eb17a54c3
--- /dev/null
+++ b/crypto/test/src/asn1/test/PrivateKeyInfoTest.cs
@@ -0,0 +1,60 @@
+using System;
+
+using NUnit.Framework;
+
+using Org.BouncyCastle.Asn1.Pkcs;
+using Org.BouncyCastle.Utilities.Encoders;
+using Org.BouncyCastle.Utilities.Test;
+
+namespace Org.BouncyCastle.Asn1.Tests
+{
+    [TestFixture]
+    public class PrivateKeyInfoTest
+        : SimpleTest
+    {
+        private static readonly byte[] priv = Base64.Decode(
+            "MC4CAQAwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC");
+
+        private static readonly byte[] privWithPub = Base64.Decode(
+            "MHICAQEwBQYDK2VwBCIEINTuctv5E1hK1bbY8fdp+K06/nwoy/HU++CXqI9EdVhC" +
+            "oB8wHQYKKoZIhvcNAQkJFDEPDA1DdXJkbGUgQ2hhaXJzgSEAGb9ECWmEzf6FQbrB" +
+            "Z9w7lshQhqowtrbLDFw4rXAxZuE=");
+
+        public override string Name
+        {
+            get { return "PrivateKeyInfoTest"; }
+        }
+
+        public override void PerformTest()
+        {
+            PrivateKeyInfo privInfo1 = PrivateKeyInfo.GetInstance(priv);
+
+            IsTrue(!privInfo1.HasPublicKey);
+
+            PrivateKeyInfo privInfo2 = new PrivateKeyInfo(privInfo1.PrivateKeyAlgorithm, privInfo1.ParsePrivateKey());
+
+            IsTrue("enc 1 failed", AreEqual(priv, privInfo2.GetEncoded()));
+
+            privInfo1 = PrivateKeyInfo.GetInstance(privWithPub);
+
+            IsTrue(privInfo1.HasPublicKey);
+
+            privInfo2 = new PrivateKeyInfo(privInfo1.PrivateKeyAlgorithm, privInfo1.ParsePrivateKey(), privInfo1.Attributes, privInfo1.PublicKeyData.GetOctets());
+
+            IsTrue("enc 2 failed", AreEqual(privWithPub, privInfo2.GetEncoded()));
+        }
+
+        public static void Main(string[] args)
+        {
+            RunTest(new PrivateKeyInfoTest());
+        }
+
+        [Test]
+        public void TestFunction()
+        {
+            string resultText = Perform().ToString();
+
+            Assert.AreEqual(Name + ": Okay", resultText);
+        }
+    }
+}