我正在尝试将以下 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)不够了解来映射函数(我也找不到任何关于如何做到这一点的体面的文章)。