Exemplo n.º 1
0
 public static string GetPemStringFromGMSSPublicKey(GMSSPublicKey key)
 {
     return($"-----BEGIN GMSS.{GMSSVersion} PUBLIC KEY-----{Environment.NewLine}{Convert.ToBase64String(key.ToBytes(), Base64FormattingOptions.InsertLineBreaks)}{Environment.NewLine}-----END GMSS PUBLIC KEY-----{Environment.NewLine}");
 }
Exemplo n.º 2
0
        private void TestEncode()
        {
            GMSSParameters     mpar  = GMSSParamSets.FromName(GMSSParamSets.GMSSParamNames.N2P10);
            GMSSKeyGenerator   mkgen = new GMSSKeyGenerator(mpar);
            IAsymmetricKeyPair akp   = mkgen.GenerateKeyPair();

            GMSSPublicKey pub = (GMSSPublicKey)akp.PublicKey;

            byte[] enc = pub.ToBytes();
            using (GMSSPublicKey pub2 = GMSSPublicKey.From(enc))
            {
                if (!pub.Equals(pub2))
                {
                    throw new Exception("EncryptionKey: public key comparison test failed!");
                }
                if (pub.GetHashCode() != pub2.GetHashCode())
                {
                    throw new Exception("EncryptionKey: public key hash test failed!");
                }
            }

            OnProgress(new TestEventArgs("Passed public key serialization"));

            MemoryStream pubstr = pub.ToStream();

            using (GMSSPublicKey pub2 = GMSSPublicKey.From(pubstr))
            {
                if (!pub.Equals(pub2))
                {
                    throw new Exception("EncryptionKey: public key comparison test failed!");
                }
                if (pub.GetHashCode() != pub2.GetHashCode())
                {
                    throw new Exception("EncryptionKey: public key hash test failed!");
                }
            }
            pubstr.Dispose();
            OnProgress(new TestEventArgs("Passed public key stream test"));

            GMSSPrivateKey pri = (GMSSPrivateKey)akp.PrivateKey;

            enc = pri.ToBytes();
            using (GMSSPrivateKey pri2 = GMSSPrivateKey.From(enc))
            {
                if (!pri.Equals(pri2))
                {
                    throw new Exception("EncryptionKey: private key comparison test failed!");
                }
                if (pri.GetHashCode() != pri2.GetHashCode())
                {
                    throw new Exception("EncryptionKey: private key hash test failed!");
                }
            }
            OnProgress(new TestEventArgs("Passed private key serialization"));

            MemoryStream pristr = pri.ToStream();

            using (GMSSPrivateKey pri2 = GMSSPrivateKey.From(pristr))
            {
                if (!pri.Equals(pri2))
                {
                    throw new Exception("EncryptionKey: private key comparison test failed!");
                }
                if (pri.GetHashCode() != pri2.GetHashCode())
                {
                    throw new Exception("EncryptionKey: private key hash test failed!");
                }
            }
            pristr.Dispose();
            OnProgress(new TestEventArgs("Passed private key stream test"));

            pri.Dispose();
            pub.Dispose();
        }