C#使用IKVM来实现与java互通的RSA签名

1、nuget中安装IKVM

2、然后使用以下方法即可:

using com.sun.org.apache.xml.@internal.security.utils;
using java.security;
using java.security.spec;

namespace ConsoleApp1
{
    public class AESTool
    {
        private static string Sign(string content, string privateKey)
        {
            PKCS8EncodedKeySpec priPKCS8 = new PKCS8EncodedKeySpec(Base64.decode(privateKey));
            KeyFactory keyf = KeyFactory.getInstance("RSA");
            PrivateKey priKey = keyf.generatePrivate(priPKCS8);
            Signature signature = Signature.getInstance("SHA1WithRSA");
            signature.initSign(priKey);
            signature.update(System.Text.Encoding.Default.GetBytes(content));
            byte[] signed = signature.sign();
            return Base64.encode(signed);
        }
    }
}

 

posted @ 2020-09-22 09:34  microsoft_xin  阅读(429)  评论(0编辑  收藏  举报