はここラースにありがとうございました:http://blog.oddbit.com/2011/05/09/signing-data-with-ssh-agent/
e
は、公開指数のPythonのlong
です。 n
は公開ModulusのPython long
です。
import M2Crypto
key = M2Crypto.RSA.new_pub_key((
M2Crypto.m2.bn_to_mpi(M2Crypto.m2.hex_to_bn(hex(e)[2:])),
M2Crypto.m2.bn_to_mpi(M2Crypto.m2.hex_to_bn(hex(n)[2:])),
))
進ソート0xA45E
の16進数文字列を生成しますので、彼はちょうど0x
後にすべてのものをつかんだ:彼は掲載
コードはでした。
私はファイルからキーを読んでいるので、長い間持っていません。私は使用を終了しました:
import M2Crypto
from binascii import hexlify
e = f.read(4)
n = f.read(0x80)
key = M2Crypto.RSA.new_pub_key((
M2Crypto.m2.bn_to_mpi(M2Crypto.m2.hex_to_bn(hexlify(e))),
M2Crypto.m2.bn_to_mpi(M2Crypto.m2.hex_to_bn(hexlify(n))),
))
チャームのように働いた!
new_pub_key
の受け入れフォーマットは、ドキュメントごとに、
のOpenSSLのMPINT形式にする必要がある - ビット
の 適切な数に続く4バイトのビッグエンディアンのビット数
これはタイプミスかどうかわかりませんが、私の指数(16進数)は00010001
で、000003010001
になりました。私はバイトカウントではなく、ビットカウントだと思う。彼らはまた、最初の0x00を削除しました。私はそれが標準かどうか、それが空のバイトであったかどうかわかりません。
編集:私はフォーマットの理解を少ししていると思います。
最初のバイトが負の場合、ゼロバイトが先頭に追加されます。 先頭にゼロバイトがある場合、最初のバイトが負にならない限り、それらは取り除かれます。この場合、0バイトだけが残されます。
いくつかの例:
Unformatted:
\x23\x24\x25\x26
Formatted:
\x00\x00\x00\x04\x23\x24\x25\x26
Explanation:
String left as is and count of bytes packed in
Unformatted:
\x00\x23\x55\x35
Formatted:
\x00\x00\x00\x03\x23\x55\x35
Explanation:
leading zero byte removed, byte count now 3
Unformatted:
\x80\x43\x55\x27
Formatted:
\x00\x00\x00\x05\x00\x80\x43\x55\x27
Explanation:
leading zero byte added because \x80 is negative
Unformatted:
\x00\xff\x43\x23
Formatted:
\x00\x00\x00\x04\x00\xff\x43\x23
Explanation:
Leading zero byte left because \xff is negative
Unformatted:
\x23\x53\66\x00
Formatted:
\x00\x00\x00\x04\x23\x53\66\x00
Explanation:
Trailing zero byte left in string