当前位置: 首页>>代码示例>>C#>>正文


C# DSACryptoServiceProvider.ExportParameters方法代码示例

本文整理汇总了C#中System.Security.Cryptography.DSACryptoServiceProvider.ExportParameters方法的典型用法代码示例。如果您正苦于以下问题:C# DSACryptoServiceProvider.ExportParameters方法的具体用法?C# DSACryptoServiceProvider.ExportParameters怎么用?C# DSACryptoServiceProvider.ExportParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.DSACryptoServiceProvider的用法示例。


在下文中一共展示了DSACryptoServiceProvider.ExportParameters方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: DoTest

        public static void DoTest()
        {
            Console.WriteLine("使用  DSACryptoServiceProvider 类创建哈希值的数字签名,然后验证签名的例子!");

            // 创建一个   DSA 算法的加密服务提供程序 (CSP) 实现的包装对象.
            DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();

            // 需要被签名的数据.
            byte[] HashValue = { 59, 4, 248, 102, 77, 97, 142, 201, 210, 12, 224, 93, 25, 41, 100, 197, 213, 134, 130, 135 };

            Console.WriteLine("初始 Hash 数据.");
            ByteArrayOutput.Print(HashValue);

            // 签名处理.
            byte[] SignedHashValue = DSASignHash(HashValue, DSA.ExportParameters(true), "SHA1");

            Console.WriteLine("使用私钥签名的数据.");
            ByteArrayOutput.Print(SignedHashValue);

            // 验证签名.
            if (DSAVerifyHash(HashValue, SignedHashValue, DSA.ExportParameters(false), "SHA1"))
            {
                Console.WriteLine("使用公钥验证 签名是有效的!");
            }
            else
            {
                Console.WriteLine("使用公钥验证 签名无效.");
            }
        }
开发者ID:mahuidong,项目名称:my-csharp-sample,代码行数:29,代码来源:DSACSPSample.cs

示例2: Main

        static void Main(string[] args)
        {
            try
            {
                DSAParameters privatekeyinfo;
                DSAParameters publickeyinfo;

                //Create a new instance of DSACryptoServiceProvider to generate a new key pair.
                using(DSACryptoServiceProvider DSA = new DSACryptoServiceProvider())
                {
                    privatekeyinfo = DSA.ExportParameters(true);
                    publickeyinfo = DSA.ExportParameters(false);
                    byte[] HashValue;

                    using(FileStream fs = new FileStream(@"C:\Listener.txt", FileMode.Open, FileAccess.Read))
                    {
                        BinaryReader reader = new BinaryReader(fs);

                        HashValue = reader.ReadBytes((int)fs.Length);

                        //HashValue = new byte[fs.Length];
                        //fs.Read(HashValue, 0, (int)fs.Length);

                        //The hash value to sign
                        //HashValue = new byte[20]{
                        //                            59, 4, 248, 102, 77, 97, 142, 201,
                        //                            210, 12, 224, 93, 25, 41, 100, 197,
                        //                            213, 134, 130, 135
                        //                        };
                    }

                    string OId = CryptoConfig.MapNameToOID("SHA1");

                    //The value to hold the signed value.
                    byte[] SignedHashValue = DSASignHash(HashValue, privatekeyinfo, OId);

                    //Verify the hash and display the results.
                    bool verified = DSAVerifyHash(HashValue, SignedHashValue, publickeyinfo, "SHA1");

                    if(verified)
                    {
                        Console.WriteLine("The hash value was verified.");
                    }
                    else
                    {
                        Console.WriteLine("The hash value was not verified.");
                    }
                }

                Console.ReadKey();
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
开发者ID:Rafael-Miceli,项目名称:ProjectStudiesCert70-536,代码行数:56,代码来源:Program.cs

示例3: TestMethodSendPrivateMessage

        public void TestMethodSendPrivateMessage()
        {
            ASCIIEncoding encoding = new ASCIIEncoding();

            DSACryptoServiceProvider mycryptoC = new DSACryptoServiceProvider();
            DSAParameters publickeyC = mycryptoC.ExportParameters(false);

            DSACryptoServiceProvider mycryptoW = new DSACryptoServiceProvider();
            DSAParameters publickeyW = mycryptoW.ExportParameters(false);

            byte[] hashC = mycryptoC.SignData(encoding.GetBytes("Cuddy"));
            byte[] hashW = mycryptoW.SignData(encoding.GetBytes("Wilson"));

            ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();

            a.Register("Cuddy", "iluvhouse", hashC, publickeyC.Counter, publickeyC.G, publickeyC.J, publickeyC.P, publickeyC.Q, publickeyC.Seed, publickeyC.X, publickeyC.Y);
            a.Register("Wilson", "ihatehouse", hashW, publickeyW.Counter, publickeyW.G, publickeyW.J, publickeyW.P, publickeyW.Q, publickeyW.Seed, publickeyW.X, publickeyW.Y);

            string message = "je suis jalouse de Cameron";
            byte[] messagesigned = mycryptoC.SignData(encoding.GetBytes(message));

            Assert.AreEqual(true,a.SendPrivateMessage("Cuddy", "Wilson", message, messagesigned));
            Assert.AreEqual(false, a.SendPrivateMessage("Cuddy", "Foreman", message, messagesigned));

            File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
            File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:27,代码来源:UnitTestSendPrivateMessage.cs

示例4: TestMethodReceivePrivateMessage

        public void TestMethodReceivePrivateMessage()
        {
            ASCIIEncoding encoding = new ASCIIEncoding();

            DSACryptoServiceProvider mycryptoC = new DSACryptoServiceProvider();
            DSAParameters publickeyC = mycryptoC.ExportParameters(false);

            DSACryptoServiceProvider mycryptoW = new DSACryptoServiceProvider();
            DSAParameters publickeyW = mycryptoW.ExportParameters(false);

            byte[] hashC = mycryptoC.SignData(encoding.GetBytes("Cuddy"));
            byte[] hashW = mycryptoW.SignData(encoding.GetBytes("Wilson"));

            ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();

            a.Register("Cuddy", "iluvhouse", hashC, publickeyC.Counter, publickeyC.G, publickeyC.J, publickeyC.P, publickeyC.Q, publickeyC.Seed, publickeyC.X, publickeyC.Y);
            a.Register("Wilson", "ihatehouse", hashW, publickeyW.Counter, publickeyW.G, publickeyW.J, publickeyW.P, publickeyW.Q, publickeyW.Seed, publickeyW.X, publickeyW.Y);

            string message = "je suis jalouse de Cameron";
            byte[] messagesigned = mycryptoC.SignData(encoding.GetBytes(message));

            a.SendPrivateMessage("Cuddy", "Wilson", message, messagesigned);
            UnitTest.ServiceReference1.Message[] b = a.ReceivePrivateMessage("Wilson", hashW);

            Assert.AreEqual("Cuddy", b[0].Auteur); //j'avoue les test sont moisi... mais je voulais juste verifier si le retour par une classe implemente dans le webservice etait possible
            Assert.AreEqual("je suis jalouse de Cameron", b[0].Text);

            File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
            File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:30,代码来源:UnitTestReceivePrivateMessage.cs

示例5: DigitalSignatureAlgorithm_compare_parameters_generation_with_original_Pidgin_OffTheRecord_data

        public void DigitalSignatureAlgorithm_compare_parameters_generation_with_original_Pidgin_OffTheRecord_data()
        {
            // Arrange
            const string p =
                "AEC0FBB4CEA96EF8BDD0E91D1BA2F6641B6535CBDA8D739CC2898FE7B472865AB60AD2B1BAA2368603C7439E63BC2F2F33D422E70173F70DB738DF5979EAEAF3CAC343CBF711960E16786703C80DF0734D8330DC955DA84B521DAB5C729202F1244D805E6BF2CC7A7142CAD74BE5FFFC14B9CCB6CABB7DB10A8F2DDB4E82383F";
            const string q = "A2A2BC20E2D94C44C63608479C79068CE7914EF3";
            const string g =
                "69B9FC5A73F3F6EA3A86F8FA3A203F42DACDC3A1516002025E5765A9DCB975F348ACBBA2116230E19CE3FC5256546FD168A2940809BDA8655771967E9CD90AF44D2C20F97F448494213A775E23607F33C255A9A74E2A5FC7B4D50BAD024D7EFAC282E67332D51A5F69239011FE058D7E75E97A788FBD5B3BAD796B2C6D8C6C3E";
            const string y =
                "9931144F3059D92FCB2AAC03B130DAE43ED1EF30AA2F0E670C3974C3E80C7110D1A60210F92479D7F640C20E1F16E01B4A72FF8D45443B01EBE2D67DF49791CAC6191B159AC39446EB6A2EA597B6B678CC3157AECEAB12A804CF0772068A942EC819138EDD6005620FE746522FF408BBC8211ABD9D6016AA46EEC87F3F04CFA4";
            const string x = "48BFDA215C31A9F0B226B3DB11F862450A0F30DA"; /* private key */

            // Act
            var param = new DSAParameters();
            param.X = General.StringToByteArray(x);
            param.P = General.StringToByteArray(p);
            param.Q = General.StringToByteArray(q);
            param.G = General.StringToByteArray(g);
            param.Y = General.StringToByteArray(y);

            var dsa = new DSACryptoServiceProvider(1024);
            dsa.ImportParameters(param);
            DSAParameters output = dsa.ExportParameters(true);

            // Assert
            param.X.SequenceEqual(output.X).Should().BeTrue();
            param.P.SequenceEqual(output.P).Should().BeTrue();
            param.Q.SequenceEqual(output.Q).Should().BeTrue();
            param.G.SequenceEqual(output.G).Should().BeTrue();
            param.Y.SequenceEqual(output.Y).Should().BeTrue();
        }
开发者ID:eXcomm,项目名称:otr-1,代码行数:31,代码来源:DigitalSignatureAlgorithmTests.cs

示例6: init

        public void init(int key_size)
        {
            //			KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
            //			keyGen.initialize(key_size, new SecureRandom());
            //			KeyPair pair = keyGen.generateKeyPair();
            //			PublicKey pubKey=pair.getPublic();
            //			PrivateKey prvKey=pair.getPrivate();

            DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(key_size);
            DSAParameters DSAKeyInfo = dsa.ExportParameters(true);

            //			x=((DSAPrivateKey)prvKey).getX().toByteArray();
            //			y=((DSAPublicKey)pubKey).getY().toByteArray();
            //
            //			DSAParams _params=((DSAKey)prvKey).getParams();
            //			p=_params.getP().toByteArray();
            //			q=_params.getQ().toByteArray();
            //			g=_params.getG().toByteArray();

            x = DSAKeyInfo.X;
            y = DSAKeyInfo.Y;
            p = DSAKeyInfo.P;
            q = DSAKeyInfo.Q;
            g = DSAKeyInfo.G;
        }
开发者ID:akrisiun,项目名称:SharpSSH,代码行数:25,代码来源:KeyPairGenDSA.cs

示例7: Enregister

        private void Enregister()
        {
            mycrypto = new DSACryptoServiceProvider();
            ASCIIEncoding encoding = new ASCIIEncoding();

            _publicKey = mycrypto.ExportParameters(false);
            byte[] tab = encoding.GetBytes(_pseudo);
            byte[] hash = mycrypto.SignData(tab);
            _myServer.ReceiveKey(tab, hash, _publicKey);
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:10,代码来源:Client.cs

示例8: init

        public void init(int key_size)
        {
            DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(key_size);
            DSAParameters DSAKeyInfo = dsa.ExportParameters(true);

            m_x = DSAKeyInfo.X;
            m_y = DSAKeyInfo.Y;
            m_p = DSAKeyInfo.P;
            m_q = DSAKeyInfo.Q;
            m_g = DSAKeyInfo.G;
        }
开发者ID:x893,项目名称:SharpSSH,代码行数:11,代码来源:KeyPairGenDSA.cs

示例9: EncodePublicKey

        public void EncodePublicKey(IPublicKey publicKey, ByteBuf buffer)
        {
            var dsa = new DSACryptoServiceProvider();
            var dsap = dsa.ExportParameters(false);


            var rsa = new RSACryptoServiceProvider();
            var rsap = rsa.ExportParameters(false);


        }
开发者ID:pacificIT,项目名称:TomP2P.NET,代码行数:11,代码来源:DsaSignatureFactory.cs

示例10: TestMethodCHangeNick

        public void TestMethodCHangeNick()
        {
            DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
            DSAParameters Publickey = mycrypto.ExportParameters(false);
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] hash = mycrypto.SignData(encoding.GetBytes("Cuddy"));
            ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();

            a.Register("Cuddy", "passbidon", hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y);
            Assert.AreEqual(true, a.ChangeNick("Cuddy", "MissC", mycrypto.SignData(encoding.GetBytes("MissC"))));
            hash = mycrypto.SignData(encoding.GetBytes("MissC"));
            Assert.AreEqual(true, a.LogIn("MissC", "passbidon", hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:13,代码来源:UnitTestChangeNick.cs

示例11: PrivateKey

        internal PrivateKey(DSAParameters dsaParameters)
        {
            privateKey = dsaParameters;

            var dsa = new DSACryptoServiceProvider(1024);
            dsa.ImportParameters(privateKey);
            PublicKey = dsa.ExportParameters(false);

            PublicKeyAsMPI = MultiPrecisionInteger.ByteArrayToMpi(PublicKey.P)
                .Concat(MultiPrecisionInteger.ByteArrayToMpi(PublicKey.Q))
                .Concat(MultiPrecisionInteger.ByteArrayToMpi(PublicKey.G))
                .Concat(MultiPrecisionInteger.ByteArrayToMpi(PublicKey.Y))
                .ToArray();
        }
开发者ID:eXcomm,项目名称:otr-1,代码行数:14,代码来源:PrivateKey.cs

示例12: GenerateKeyPair

        public bool GenerateKeyPair(string pubPath, string privPath)
        {
            try
            {
                using (DSACryptoServiceProvider dsaProvider = new DSACryptoServiceProvider())
                {

                    DSAParameters publicKey = dsaProvider.ExportParameters(false);//pub
                    var binformt = new BinaryFormatter();
                    using (var fs = new FileStream(pubPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
                    {
                        //binformt.Serialize(fs, publicKey.Counter);

                        binformt.Serialize(fs, publicKey.Q);
                        binformt.Serialize(fs, publicKey.Seed);
                        binformt.Serialize(fs, publicKey.G);
                        binformt.Serialize(fs, publicKey.P);
                        binformt.Serialize(fs, publicKey.Counter);
                        binformt.Serialize(fs, publicKey.Y);
                        //binformt.Serialize(fs, publicKey.X);
                        binformt.Serialize(fs, publicKey.J);
                        fs.Close();
                    }
                    //File.WriteAllBytes(pubPath, memoryStream.GetBuffer());

                    DSAParameters privateKey = dsaProvider.ExportParameters(true);//generate private key
                    var binformt1 = new BinaryFormatter();
                    //var memoryStream1 = new MemoryStream();
                    using (var fs = new FileStream(privPath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.Write))
                    {
                        binformt.Serialize(fs, privateKey.Q);
                        binformt.Serialize(fs, privateKey.Seed);
                        binformt.Serialize(fs, privateKey.G);
                        binformt.Serialize(fs, privateKey.P);
                        binformt.Serialize(fs, privateKey.Counter);
                        binformt.Serialize(fs, privateKey.Y);
                        binformt.Serialize(fs, privateKey.X);
                        binformt.Serialize(fs, privateKey.J);
                        fs.Close();
                    }
                    //File.WriteAllBytes(privPath, memoryStream1.GetBuffer());
                    //File.WriteAllBytes(privPath, keyData);
                }
            }
            catch (Exception ex)
            {
                return false;
            }
            return true;
        }
开发者ID:ShlikhutkaBohdan,项目名称:nulp_SoftwareSecurity,代码行数:50,代码来源:DssUnit.cs

示例13: TestMethodSerialization

        public void TestMethodSerialization()
        {
            //on simule l'ajout d'auteur
            User aut1 = new User("Toto", "mypass1");
            User aut2 = new User("JC", "mypass2");
            User aut3 = new User("Max", "mypass3");
            User aut4 = new User("Titi", "clearstream");
            User aut5 = new User("Toadd", "serie");

            DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
            DSAParameters key = mycrypto.ExportParameters(false);
            aut1.Publickey = key;
            aut2.Publickey = key;
            aut3.Publickey = key;
            aut4.Publickey = key;
            aut5.Publickey = key;

            Message mess1 = new Message(aut1.Login, "Coucou ca va?");
            Message mess2 = new Message(aut2.Login, "oue et toi?");
            Message mess3 = new Message(aut3.Login, "tranquille!");
            Message mess4 = new Message(aut1.Login, "ca va ca va");
            Message mess5 = new Message(aut5.Login, "Test fifi");
            Message mess6 = new Message(aut5.Login, "MessagePrive: cool ma poule?");

            aut1.AddPrivateMessage(mess6);

            //on simule
            Chat toTest = new Chat();
            Chat toOut =  new Chat();
            toTest.AddUser(aut1);
            toTest.AddUser(aut2);
            toTest.AddUser(aut3);
            toTest.AddUser(aut4);
            toTest.AddMessage(mess1);
            toTest.AddMessage(mess2);
            toTest.AddMessage(mess3);
            toTest.AddMessage(mess4);

            toTest.Serialiser();
            toOut.Deserialiser();
            toOut.AddUser(aut5);
            toOut.AddMessage(mess5);
            toOut.Serialiser();
            //l'analyse du test se fera manuellement dans le fichier de sortie
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:45,代码来源:UnitTestSerialization.cs

示例14: PrincipalForm

        /// <summary>
        /// Constructeur par defaut
        /// </summary>
        public PrincipalForm()
        {
            InitializeComponent();
            SaveForm param_fenetre = Serializer.DeserialiserFenetre();
            if (param_fenetre != null)
            {
                this.Size = new System.Drawing.Size(param_fenetre.Weightform, param_fenetre.Heightform);
                this.splitContainer1.SplitterDistance = param_fenetre.Splitterdistance;
                this.Location = new System.Drawing.Point(param_fenetre.LocalisationX, param_fenetre.LocalisationY);
            }

            //initialisation de liaison avec le service
            client = new ServeurChat.ServeurChatSoapClient();
            //generation des clé pour la session qui va etre lance
            crypto = new DSACryptoServiceProvider();
            securitykey = crypto.ExportParameters(false);
            connected = false;
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:21,代码来源:PrincipalForm.cs

示例15: TestMethodRegisterAndLogin

        public void TestMethodRegisterAndLogin()
        {
            DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
            DSAParameters Publickey = mycrypto.ExportParameters(false);
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] hash = mycrypto.SignData(encoding.GetBytes("Cuddy"));
            ServiceReference1.ServeurChatSoapClient a = new ServiceReference1.ServeurChatSoapClient();

            Assert.AreEqual(true, a.Register("Cuddy", "passbidon",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
            Assert.AreEqual(false, a.Register("Cuddy", "rate",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));

            Assert.AreEqual(true,a.LogIn("Cuddy", "passbidon",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));
            Assert.AreEqual(false, a.LogIn("Cuddy", "badpass",hash, Publickey.Counter, Publickey.G, Publickey.J, Publickey.P, Publickey.Q, Publickey.Seed, Publickey.X, Publickey.Y));

            //remise a zero du serveur
            File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\Message_serialization.xml");
            File.Delete("C:\\Program Files\\Common Files\\microsoft shared\\DevServer\\10.0\\User_serialization.xml");
        }
开发者ID:ulricheza,项目名称:Isima,代码行数:18,代码来源:UnitTestConnexion.cs


注:本文中的System.Security.Cryptography.DSACryptoServiceProvider.ExportParameters方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。