本文整理汇总了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");
}
示例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");
}
示例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));
}
示例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);
}
示例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);
}
示例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");
}
示例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);
}
}
示例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);
}
示例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");
}
示例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");
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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 });
}
}
}