欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

dsa java_将Java转换为python DSA签名

发布时间:2023/12/15 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 dsa java_将Java转换为python DSA签名 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

有人知道我将如何将java代码转换成python吗?在/**

* signs the data for the account account

*/

private byte[] sign(String pkStr,byte[] data, String keyType) throws Exception {

BASE64Decoder decoder = new BASE64Decoder();

KeyFactory keyFac = null;

//instantiate the key factory based on the key alg type

if(keyType.equals("DSA")){

keyFac = KeyFactory.getInstance("DSA");

}else if(keyType.equals("RSA")){

keyFac = KeyFactory.getInstance("RSA");

}

//generate the public key

PKCS8EncodedKeySpec dprks = new PKCS8EncodedKeySpec(decoder.decodeBuffer(pkStr));

PrivateKey pk = keyFac.generatePrivate(dprks);

return(signBytes(data,pk,keyType));

}

/**

* sign the data with the key

*/

private byte[] signBytes(byte [] data,

PrivateKey signingPrivateKey, String keyType)throws Exception {

Signature dsa = null;

//instantiate the signature alg based on the key type

if(keyType.equals("DSA")){

dsa = Signature.getInstance("SHA1withDSA");

}else if(keyType.equals("RSA")){

dsa = Signature.getInstance("SHA1withRSA");

}

/* Initializing the object with a private key */

dsa.initSign(signingPrivateKey);

/* Update and sign the data */

dsa.update(data);

byte[] sig = dsa.sign();

return sig;

}

“keyType”似乎总是被传递为“DSA”,所以我研究了M2Crypto.DSA,这看起来很有前途。这个数字签名但是,函数返回一个由2字节字符串组成的元组,我根本不知道该如何处理。在

总结

以上是生活随笔为你收集整理的dsa java_将Java转换为python DSA签名的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。