将C#代码转换为java 谢谢大家 急求
byte[]plainTxtBytes=Encoding.UTF-8.GetBytes(PlainText);SHA256md5=SHA256.Create();byte...
byte[] plainTxtBytes =Encoding.UTF-8.GetBytes(PlainText);
SHA256 md5 = SHA256.Create();
byte[] hashString = md5.ComputeHash(plainTxtBytes);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
//加签
rsa.FromXmlString(PrivateKey);//私钥证书
RSAPKCS1SignatureFormatter rsaSign = new RSAPKCS1SignatureFormatter(rsa);
rsaSign.SetHashAlgorithm(DigestAlg);
byte[] bytes = rsaSign.CreateSignature(hashString); 展开
SHA256 md5 = SHA256.Create();
byte[] hashString = md5.ComputeHash(plainTxtBytes);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
//加签
rsa.FromXmlString(PrivateKey);//私钥证书
RSAPKCS1SignatureFormatter rsaSign = new RSAPKCS1SignatureFormatter(rsa);
rsaSign.SetHashAlgorithm(DigestAlg);
byte[] bytes = rsaSign.CreateSignature(hashString); 展开
展开全部
byte[] plainTxtBytes=plainText.getBytes("UTF-8");
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(plainTxtBytes);
byte[] hashString = messageDigest.digest();
//加签
PKCS8EncodedKeySpec priv_spec = new PKCS8EncodedKeySpec(privateKey);
KeyFactory mykeyFactory = KeyFactory.getInstance("RSA");
PrivateKey privKey = mykeyFactory.generatePrivate(priv_spec);
Signature sig = Signature.getInstance("SHA1withRSA");
sig.initSign(privKey);
sig.update(hashString);
sig.sign();
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
messageDigest.update(plainTxtBytes);
byte[] hashString = messageDigest.digest();
//加签
PKCS8EncodedKeySpec priv_spec = new PKCS8EncodedKeySpec(privateKey);
KeyFactory mykeyFactory = KeyFactory.getInstance("RSA");
PrivateKey privKey = mykeyFactory.generatePrivate(priv_spec);
Signature sig = Signature.getInstance("SHA1withRSA");
sig.initSign(privKey);
sig.update(hashString);
sig.sign();
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询