当前位置:  开发笔记 > 编程语言 > 正文

Python M2Crypto - 生成DSA密钥对并分离公共/私有组件

如何解决《PythonM2Crypto-生成DSA密钥对并分离公共/私有组件》经验,为你挑选了1个好方法。

任何人都可以解释以下原因:

>>> from M2Crypto import DSA, BIO
>>> dsa = DSA.gen_params(1024)
..+........+++++++++++++++++++++++++++++++++++++++++++++++++++*
............+.+.+..+.........+.............+.....................+.
...+.............+...........+.........................................
+.........+................+..........+......+..+.+...+..........+..+..
..+...+......+....+.............+.................+.......+.........+..
....+......+.+..+..........+........+.+...+..+...............+.........
..+.....+........+..........+++++++++++++++++++++++++++++++++++++++++++
++++++++*
>>> mem = BIO.MemoryBuffer()
>>> dsa.save_key_bio(mem, cipher=None)
1
>>> dsa.save_pub_key_bio(mem)
0
>>> print mem.getvalue()
-----BEGIN DSA PRIVATE KEY-----
MIIBIgIBAAKBgQDPGRFSTqqx8vet5kaW5m99A83REotTcX9HOv+zrqMxQpaTlinS
MDz49I4psDPJ+bWH7vySEdOYO2JGUj6kYZdz/ZwyNjphWNjQkaUrmfaVLzS3PHpW
aMrPEweLesf/PT4KXm2HaDbaW/g2Ds5h+Zlq9LDKcN2vfvyeiTCmf1esyQIVAO9I
ippU4PIdvJVO9HQRkqrD2bxPAoGBAIwVgM7dgNVwihJva6qeeh7ypy3ESNB9k8nY
fOnES+SqZGQbkPrJIusRCJNKERiMATJXNRMfBeWD8htNRezbgtr0OpuYSBurAQjp
hKKVI3DHSv7XT49BQ3tdJww8lQfkOhHOfFTG6U1dJhWdggp0WN3EjYlt77agRsjR
4t5sD1f3
-----END DSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
-----END PUBLIC KEY-----
>>>

很明显我错过了一些东西.M2Crypto不存在的文档没有帮助.



1> Ali Afshar..:

调用dsa.gen_key(),然后保存.您实际上并没有生成公钥.

>>> from M2Crypto import DSA, BIO
>>> dsa = DSA.gen_params(1024)
..+..etc
>>> mem = BIO.MemoryBuffer()
>>> dsa.gen_key()
>>> dsa.save_key_bio(mem, cipher=None)
1
>>> dsa.save_pub_key_bio(mem)
1
>>> print mem.getvalue()
-----BEGIN DSA PRIVATE KEY-----
MIIBuwIBAAKBgQDowiLFDXGwaWIOkZybeeqSXYZ8KCLmXg5XfnAtDBlVOokB91Rj
etc.
-----END DSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIIBtzCCASsGByqGSM44BAEwggEeAoGBAOjCIsUNcbBpYg6RnJt56pJdhnwoIuZe
Dld+cC0MGVU6iQH3VGNEzKycBVQeVYke3itZwQALSlT2JfUsmOjeZYIkc9l2YYob
rixObXfQyc0AOBM/J53F0F6R8+xvEwN/Hmdd9SjjbdZi8gve+dr9UfnKHXi0KPUF
s2ougGhXeEjTAhUAiW5bMzG8nCVjXErgwaDEx+JEdtECgYACba2quw3xibhT3JNd
sDh0gIRpHPQgIgxgzGv6A09Vdb4VgtWf0MYAo6gAhxsZIWWKzQ94Oe1nf7OhC+B+
VjT+PW+ExSrbJVONTN5ycE64O7+2L+q/hZSjjkxXgfcApqeVtZp4wKqbS976Kpch
WgNl0zdkvV8JddRs0oKQ0Bl7dwOBhQACgYEAgkdF/+ncobVcYXfXHBUH3H5SLD3y
u2zUWGhXM4/MUTwPromDOQ8Zd0H7myYhmQvVUb+J9mJHMIn7Guf4JDH+8d6rBpzo
U5yEGqgsSqYqgtStzDvsKHfqw3mvjvsktm66N/vm36eai2I6J15QibdtP0lb1Um8
EeECDTxWUWT93rs=
-----END PUBLIC KEY-----

>>> 

推荐阅读
贴进你的心聆听你的世界
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有