java 到 python 转换:x509 / dsa / sha1withdsa 加密如何?
我有以下 Java 代码,我正在尝试将其转换为 python,但我不太确定如何执行此操作:
import java.security.spec.X509EncodedKeySpec;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
byte[] key = KeyReader.read(filestream)
//KeyReader.read(inputstream) just reads in the bytes 1 at a time from the filestream
X509EncodedKeySpec pubKey = new X509EncodedKeySpec(key);
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
PublicKey pub = keyFactory.generatePublic(pubKey);
Signature signature = Signature.getInstance("SHA1withDSA");
signature.initVerify(pub)
signature.update(a_byte_string) //doesn't matter
我对如何在 python 中执行此操作有点迷失。具体来说,SHA1withDSA 部分。我只是对 python 加密库(确切地说是 m2crypto)了解不够,无法映射函数(我也找不到任何关于如何做到这一点的像样的文章)。
I've got the following Java code that I'm trying to convert to python, and I'm not really sure how to do this:
import java.security.spec.X509EncodedKeySpec;
import java.security.KeyFactory;
import java.security.PublicKey;
import java.security.Signature;
byte[] key = KeyReader.read(filestream)
//KeyReader.read(inputstream) just reads in the bytes 1 at a time from the filestream
X509EncodedKeySpec pubKey = new X509EncodedKeySpec(key);
KeyFactory keyFactory = KeyFactory.getInstance("DSA");
PublicKey pub = keyFactory.generatePublic(pubKey);
Signature signature = Signature.getInstance("SHA1withDSA");
signature.initVerify(pub)
signature.update(a_byte_string) //doesn't matter
I'm kinda lost as to how to do this in python. Specifically, the SHA1withDSA part. I just don't know enough about the python crypto libs (m2crypto to be exact) to map the functions (nor could I find any decent writeups on how to do this).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不太明白Java代码,但这就是你想要做的吗?
I don't exactly understand the Java code, but is this what you are trying to do?