小弟请教DSACryptoServiceProvider的用法,我怎么才能验证正确??
我是这样做的DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();
byte[] DSAHash = Encoding.ASCII.GetBytes("12345678901234567890");
然后写了个xml配置
<DSAKeyValue>
<P>xxxxxxxxxx</P>
<Q>xxxxxxxxxx</Q>
<G>xxxxxxxxxx</G>
<Y>xxxxxxxxxx</Y>
<J>xxxxxxxxxx</J>
<Seed>xxx</Seed>
<PgenCounter>xxx</PgenCounter>
</DSAKeyValue>
然后装入
DSA.FromXmlString("xxx.xml");
为什么运行这句老是返回 false ??怎么才能返回 true ???
DSA.VerifyData(DSAHash, "12345678901234567890");
小弟在这里谢谢各位大大,在线等` --------------------编程问答-------------------- 没用过,友情帮顶下.. --------------------编程问答-------------------- 帮帮我~`我还有100分送 --------------------编程问答-------------------- 帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~`帮帮我~` --------------------编程问答-------------------- 帮LZ顶 --------------------编程问答-------------------- 继续等待! --------------------编程问答-------------------- 帮我~` --------------------编程问答-------------------- using System;
using System.Text;
using System.Security.Cryptography;
class dsacrypto_SignData {
public static void Main(String[] args){
//先要将字符串转换为字节数组,这与编码有关。
String str = "this is a test.";
byte[] bytes = Encoding.ASCII.GetBytes(str);
//选择签名方式,有RSA和DSA
DSACryptoServiceProvider dsac = new DSACryptoServiceProvider();
byte[] sign = dsac.SignData(bytes);
//sign便是出来的签名结果。
//下面是认证了
DSACryptoServiceProvider dsac2 = new DSACryptoServiceProvider();
dsac2.FromXmlString(dsac.ToXmlString(false));
bool ver = dsac2.VerifyData(bytes, sign);
if (ver) {
Console.WriteLine("通过");
} else {
Console.WriteLine("不能通过");
}
}
}
--------------------编程问答-------------------- to hertcloud(·£孙子兵法£·)
偶先试下子,弄明白后再来拜,先谢谢一声~` --------------------编程问答-------------------- 只能友情帮顶一下 --------------------编程问答--------------------
我也遇到这个问题了,请问解决了么?
补充:.NET技术 , C#