Fan警长 2021-08-03 11:24 采纳率: 0%
浏览 158
已结题

求C#实现JAVA中SHA1withECDSA数字签名

JAVA代码如下:

//密钥
String key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

byte[] keyByte = Base64.decodeBase64(key);
PKCS8EncodedKeySpec pkcs8EncodedKeySpec = new PKCS8EncodedKeySpec(keyByte);
KeyFactory keyFactory = KeyFactory.getInstance("EC");
PrivateKey privateKey = keyFactory.generatePrivate(pkcs8EncodedKeySpec);

Signature signature = Signature.getInstance("SHA1withECDSA");
signature.initSign(privateKey);
signature.update("1122334455667788".getBytes());
byte[] res = signature.sign();
System.out.println("签名:" + Base64.encodeBase64String(res));

求C#版本实现!

  • 写回答

2条回答 默认 最新

  • Fan警长 2021-08-03 16:05
    关注

    已解决,谢谢各位!
    AsymmetricKeyParameter priKey = GetPrivateKeyParameter(key);
    byte[] byteData = System.Text.Encoding.UTF8.GetBytes(data);

            ISigner normalSig = SignerUtilities.GetSigner("SHA1withECDSA");
            normalSig.Init(true, priKey);
            normalSig.BlockUpdate(byteData, 0, byteData.Length);
            byte[] normalResult = normalSig.GenerateSignature(); //签名结果
            return Convert.ToBase64String(normalResult);
    
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 8月3日
  • 创建了问题 8月3日