我有以下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)来映射函数(也没有找到关于如何做到这一点的任何体面的文章)。
答案 0 :(得分:1)
我不完全理解Java代码,但这是你想要做的吗?
from M2Crypto import X509
x509 = X509.load_cert(filename)
assert x509.verify() == 1