【问题标题】:java to python conversion: x509 / dsa / sha1withdsa crypto howto?java 到 python 的转换:x509 / dsa / sha1withdsa crypto howto?
【发布时间】:2009-08-27 02:22:43
【问题描述】:

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

【问题讨论】:

    标签: java python cryptography sha1 m2crypto


    【解决方案1】:

    我不完全理解 Java 代码,但这是你想要做的吗?

    from M2Crypto import X509
    
    x509 = X509.load_cert(filename)
    assert x509.verify() == 1
    

    【讨论】:

      猜你喜欢
      • 2011-04-02
      • 2011-10-27
      • 2012-07-05
      • 2014-03-17
      • 2021-05-11
      • 2012-06-20
      • 2021-08-28
      • 2021-10-30
      • 2014-11-25
      相关资源
      最近更新 更多