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


C# DSACryptoServiceProvider.SignData方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: DSAEncryptPassword

 /// <summary>
 /// DSA 加密
 /// </summary>
 /// <param name="password">要加密的字符串</param>
 /// <returns>等效于此实例经过 DSA 加密密文</returns>
 public static string DSAEncryptPassword(string password)
 {
     if (password == null)
     {
         throw new ArgumentNullException("password");
     }
     DSACryptoServiceProvider ServiceProvider = new DSACryptoServiceProvider();
     string NewPassword = BitConverter.ToString(ServiceProvider.SignData(Encoding.UTF8.GetBytes(password)));
     ServiceProvider.Clear();
     return NewPassword.Replace("-", null);
 }
开发者ID:uwitec,项目名称:shop,代码行数:16,代码来源:TextEncrypt.cs

示例6: TestMethodReceiveAllMessage

        public void TestMethodReceiveAllMessage()
        {
            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();

            string message = "je suis jalouse de Cameron";
            byte[] messagesigned = mycrypto.SignData(encoding.GetBytes(message));
            a.Register("Cuddy", "iluvhouse", hash, publickey.Counter, publickey.G, publickey.J, publickey.P, publickey.Q, publickey.Seed, publickey.X, publickey.Y);
            a.SendMessage("Cuddy", message, messagesigned);

            UnitTest.ServiceReference1.Message[] b = a.ReceiveMessageNonRead("Cuddy", hash);
            UnitTest.ServiceReference1.Message[] c = a.ReceiveAllMessage("Cuddy", hash);

            Assert.AreEqual("je suis jalouse de Cameron", c[0].Text); //identique a tous les reception de message[]
            Assert.AreEqual("Cuddy", c[0].Auteur);
            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,代码行数:22,代码来源:UnitTestReceiveAllMessage.cs

示例7: Sign

        public static byte[] Sign(byte[] data, byte[] signKeyPair)
        {
            using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider())
            {
                dsa.ImportCspBlob(signKeyPair);

                if (dsa.PublicOnly)
                {
                    throw new InvalidOperationException("You must have both the public and private key");
                }

                return dsa.SignData(data);
            }
        }
开发者ID:iqman,项目名称:MACMSC,代码行数:14,代码来源:DataSigner.cs

示例8: CreateSignature

        public static string CreateSignature(string inputData, String privateKey)
        {
            // create the crypto-service provider:
            DSACryptoServiceProvider dsa = new DSACryptoServiceProvider();

            // setup the dsa from the private key:
            dsa.FromXmlString(privateKey);

            byte[] data = UTF8Encoding.ASCII.GetBytes(inputData);

            // get the signature:
            byte[] signature = dsa.SignData(data);

            return Convert.ToBase64String(signature);
        }
开发者ID:linyunfeng,项目名称:mtapi,代码行数:15,代码来源:DigitalSignatureHelper.cs

示例9: TestMethodSendMessage

        public void TestMethodSendMessage()
        {
            DSACryptoServiceProvider mycrypto = new DSACryptoServiceProvider();
            DSAParameters publickey = mycrypto.ExportParameters(false);
            DSACryptoServiceProvider petitmalin = new DSACryptoServiceProvider();
            DSAParameters Clemoisi = petitmalin.ExportParameters(false);

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

            byte[] hash = mycrypto.SignData(encoding.GetBytes("Cuddy"));
            string message = "je suis jalouse de Cameron";

            a.Register("Cuddy", "iluvhouse", hash, publickey.Counter, publickey.G, publickey.J, publickey.P, publickey.Q, publickey.Seed, publickey.X, publickey.Y);

            byte[] messagesigned = mycrypto.SignData(encoding.GetBytes(message));
            Assert.AreEqual(true, a.SendMessage("Cuddy", message, messagesigned));

            byte[] hashmoisi = petitmalin.SignData(encoding.GetBytes(message));
            Assert.AreEqual(false, a.SendMessage("Cuddy",message,hashmoisi));

            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,代码行数:24,代码来源:UnitTestSendMessage.cs

示例10: 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

示例11: Test_ImportKey

        MFTestResults Test_ImportKey(Session session)
        {
            bool testResult = false;

            try
            {
                using (CryptoKey pubkey = CryptoKey.LoadKey(session, m_publicDsaKey))
                {
                    // replace publickey with private
                    CryptokiAttribute[] privateKey = new CryptokiAttribute[m_publicDsaKey.Length];

                    for (int x = 0; x < m_publicDsaKey.Length; x++)
                    {
                        privateKey[x] = new CryptokiAttribute(m_publicDsaKey[x].Type, new byte[m_publicDsaKey[x].Value.Length]);
                        Array.Copy(m_publicDsaKey[x].Value, privateKey[x].Value, m_publicDsaKey[x].Value.Length);
                    }

                    privateKey[0].Value = Utility.ConvertToBytes((int)CryptokiClass.PRIVATE_KEY);
                    privateKey[5].Value = new byte[]
                    {
                        0x45, 0xB3, 0x34, 0x77, 0x54, 0x3E, 0x7E, 0xBC, 0x82, 0xA8, 0x4E, 0x8E, 0x91, 0x55, 0x86, 0xC1, 
                        0xDA, 0x22, 0xDE, 0x09, 
                    };

                    using (CryptoKey privkey = CryptoKey.LoadKey(session, privateKey))
                    {
                        string dataToSign = "This is a simple message to be encrypted";

                        byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(dataToSign);

                        using (DSACryptoServiceProvider dsaEncr = new DSACryptoServiceProvider(privkey))
                        using(DSACryptoServiceProvider dsaDecr = new DSACryptoServiceProvider(pubkey))
                        {
                            byte[] signature = dsaEncr.SignData(data);

                            testResult = dsaDecr.VerifyData(data, signature);
                        }
                    }

                    using (CryptoKey privkey = CryptoKey.LoadKey(session, m_privateDsaKey))
                    {
                        string dataToSign = "This is a simple message to be encrypted";

                        byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(dataToSign);

                        using (DSACryptoServiceProvider dsaEncr = new DSACryptoServiceProvider(privkey))
                        using(DSACryptoServiceProvider dsaDecr = new DSACryptoServiceProvider(privkey))
                        {
                            byte[] signature = dsaEncr.SignData(data);

                            testResult &= dsaDecr.VerifyData(data, signature);
                        }
                    }

                }
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                testResult = false;
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:64,代码来源:DsaTests.cs

示例12: TestSignature

        MFTestResults TestSignature(DSACryptoServiceProvider csp, HashAlgorithm hashAlg)
        {
            bool testResult = false;

            try
            {
                string dataToSign = "This is a simple message to be encrypted";

                byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(dataToSign);

                byte[] signature = csp.SignData(data);

                testResult = csp.VerifyData(data, signature);

                byte[] hash = hashAlg.ComputeHash(data);

                signature = csp.SignHash(hash, hashAlg.HashType);
                testResult &= csp.VerifyHash(hash, hashAlg.HashType, signature);
            }
            catch (Exception ex)
            {
                Log.Exception("Unexpected Exception", ex);
                testResult = false;
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:27,代码来源:DsaTests.cs

示例13: DsaTest_ImportRsaKeyAndUseWithDsaShouldFail

        public MFTestResults DsaTest_ImportRsaKeyAndUseWithDsaShouldFail()
        {
            bool testResult = false;

            try
            {
                using (Session session = new Session("", MechanismType.DSA))
                using (CryptoKey obj = CryptokiObject.CreateObject(session, m_privateRsaKey) as CryptoKey)
                {
                    string dataToSign = "This is a simple message to be encrypted";

                    byte[] data = System.Text.UTF8Encoding.UTF8.GetBytes(dataToSign);

                    using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(obj))
                    {
                        byte[] signature = dsa.SignData(data);

                        dsa.VerifyData(data, signature);
                    }
                }
            }
            catch (ArgumentException)
            {
                testResult = true;
            }
            catch
            {
                testResult = false;
            }

            return (testResult ? MFTestResults.Pass : MFTestResults.Fail);
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:32,代码来源:DsaTests.cs

示例14: Test

        public static Boolean Test(int keySize)
        {
            Boolean bRes = true;
            Byte[] abData = new Byte[65536];
            Byte[] abSignature = null;
            Byte[] abSignature1 = null;
            int ks = keySize;

            for (int i = 0; i < 65536; i++) abData[i] = (Byte)(i % 256);

            try
            {
                using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(ks))
                {
                    abSignature = dsa.SignData(abData);
                    abSignature1 = dsa.SignData(abData);
                    /*          if(!Compare(abSignature, abSignature1)) {
                                    Log.Comment("WRONG : two signing passes gave different signatures!");
                                    bRes = false;
                                } */
                    Log.Comment("Signature is : ");
                    PrintByteArray(abSignature);

                    if (dsa.VerifyData(abData, abSignature))
                    {
                        Log.Comment("CORRECT : Signature OK");
                    }
                    else
                    {
                        Log.Comment("WRONG : Signature is BAD");
                        bRes = false;
                    }

                    if (dsa.VerifyData(abData, abSignature1))
                    {
                        Log.Comment("CORRECT : Signature1 OK");
                    }
                    else
                    {
                        Log.Comment("WRONG : Signature1 is BAD");
                        bRes = false;
                    }

                    abData[2]++;
                    if (dsa.VerifyData(abData, abSignature))
                    {
                        Log.Comment("WRONG : Signature OK");
                        bRes = false;
                    }
                    else
                    {
                        Log.Comment("CORRECT : Signature is BAD");
                    }

                    abData[2]--;
                    abSignature[1]++;
                    if (dsa.VerifyData(abData, abSignature))
                    {
                        Log.Comment("WRONG : Signature OK");
                        bRes = false;
                    }
                    else
                    {
                        Log.Comment("CORRECT : Signature is BAD");
                    }

                    abData[2]++;
                    if (dsa.VerifyData(abData, abSignature1))
                    {
                        Log.Comment("WRONG : Signature1 OK");
                        bRes = false;
                    }
                    else
                    {
                        Log.Comment("CORRECT : Signature1 is BAD");
                    }

                    abData[2]--;
                    abSignature1[1]++;
                    if (dsa.VerifyData(abData, abSignature1))
                    {
                        Log.Comment("WRONG : Signature1 OK");
                        bRes = false;
                    }
                    else
                    {
                        Log.Comment("CORRECT : Signature1 is BAD");
                    }
                }
            }
            catch (Exception e)
            {
                Log.Comment("Exception ocured :\n" + e.ToString());
                bRes = false;
            }

            return bRes;
        }
开发者ID:aura1213,项目名称:netmf-interpreter,代码行数:98,代码来源:DSAsign_kl.cs

示例15: CSPSignNoPrivate

        /// <summary>
        ///		Sign without private key
        /// </summary>
        private static void CSPSignNoPrivate()
        {
            //DSACryptoServiceProvider dsaPriv = new DSACryptoServiceProvider();
            //byte[] publicBlob = dsaPriv.ExportCspBlob(false);

            using (Session session = new Session("", MechanismType.DSA))
            {
                CryptoKey key = CryptoKey.CreateObject(session, m_publicDsaKey) as CryptoKey;

                using (DSACryptoServiceProvider dsa = new DSACryptoServiceProvider(key))
                {
                    //dsa.ImportCspBlob(publicBlob);

                    dsa.SignData(new byte[] { 0, 1, 2, 3, 4, 5 });
                }
            }
        }
开发者ID:koson,项目名称:.NETMF_for_LPC17xx,代码行数:20,代码来源:DSA.cs


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