pythonとopensslでDSA

openssl

DSAパラメータの作成

openssl dsaparam -out dsa_param.pem 1024

-----BEGIN DSA PARAMETERS-----
MIIBHgKBgQC/8MJpdDasZUHnleniFb3VZuP0UlnBX+fMqtaVPVryTejlztaTrYbY
l/6iuEBKCQhgVgFX93VnuB33PvkbfE+x/1iRFMjqq17a2Mhpq1RudnCOs4IJWhB5
4yZLoCUMHVv/4bu2JeUiZjcJx6ImLG/0JIkb0k92y7kZ4ATwZTo4tQIVAJrpwWiq
TICj4hNECu4p5lG8kjmrAoGAC+v9bT4vPFf7YKereUgkPGToGahGKkGiTj+HVfDl
7SdPpjOT7oEBwveXpUClP6EO1T+sonj8h4rDdS0JWj39gadkdLGsVEmuiTQ9gwG0
cOyCK5o51fyO5hRljs7uH5fl2tnMQ2ce9WI3iSJZEEy8qNJYP72j2qvXW2BIsMwu
V04=
-----END DSA PARAMETERS-----

DSA秘密鍵を生成(暗号化無し)

openssl gendsa -out dsa_private.pem dsa_param.pem

-----BEGIN DSA PRIVATE KEY-----
MIIBugIBAAKBgQC/8MJpdDasZUHnleniFb3VZuP0UlnBX+fMqtaVPVryTejlztaT
rYbYl/6iuEBKCQhgVgFX93VnuB33PvkbfE+x/1iRFMjqq17a2Mhpq1RudnCOs4IJ
WhB54yZLoCUMHVv/4bu2JeUiZjcJx6ImLG/0JIkb0k92y7kZ4ATwZTo4tQIVAJrp
wWiqTICj4hNECu4p5lG8kjmrAoGAC+v9bT4vPFf7YKereUgkPGToGahGKkGiTj+H
VfDl7SdPpjOT7oEBwveXpUClP6EO1T+sonj8h4rDdS0JWj39gadkdLGsVEmuiTQ9
gwG0cOyCK5o51fyO5hRljs7uH5fl2tnMQ2ce9WI3iSJZEEy8qNJYP72j2qvXW2BI
sMwuV04CgYBPH//rcSlW8uGLSta/8BOi0HKVQPoRDZqP/Y8v7UOqqzaetrkhkKeP
Kq0/QUziUoRH5WFp1w7kJUwc55rTszd2V4hgw1i81SZASo6puknXCieIzgntQJip
/aH5Whv9Fj6O92dmru6R+ubveUCbvs1rnDJ/bMtLDO/QpCn5EZ2C6wIUYn6d1YHb
h0HOwo8XKYpzPeRxcjI=
-----END DSA PRIVATE KEY-----

DSA秘密鍵を生成。des3で暗号化

openssl gendsa -out dsa_private_des3.pem -des3 dsa_param.pem

-----BEGIN DSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,C8FA2B73176F5312

XYcYfrQkOW8huU7g4ZqiW7GEHykiM9uvt6zQCO7tXfmB2qbRrAMSrC/JEWeurtBh
hnjc83RfyURzTjkBjLKFt9HMfj4LqMaVqiLUKj767nmOqf/joo9XPOgFYQu1l89H
0h5LimKldIHAueQiGiTYSxYzEc/ZO0lzul+vCbS9hj7eAV52KIMPxzxMlHT/y4Jt
bRckLIialRbMT8OXYciTDh9ro84gBTZ6lLgde/P35iCPrIdoCjoQbs+pfLySg/d9
Sk4/bdbiUMr6L+99hEvsH+i6CHELP+8/YzhfqE763EDPZX6PvGlcVWQuDr/Qpnyv
n5vpG0hBQ4e2Q37AmXr3AC54Lo/8QXdKBUiWPgBvWWQragqDfjLgf6DT0SJ6q1Bs
w6KSvw0bxXr/X3SfdIUMqCKnDgnMef7euxwgE1Su8ZQ25HWNuEQPzbNiNA5LQ0Te
h8NesXYd4VchbQkVkqonZl6TJzxze4ifLzjlGdgngVMQd4oWhxXYuiopbHlHfrIM
vv5mJvgPr7R6quffWXDFc+49HABaoSv2CaVnQ/1StMuOnRrWakK5TV6/Lz9Ww0eV
KRE608B3xxlVARTywagmFQ==
-----END DSA PRIVATE KEY-----

秘密鍵に対応する公開鍵を出力

openssl dsa -in dsa_private.pem -pubout -out dsa_public.pem

-----BEGIN PUBLIC KEY-----
MIIBtjCCASsGByqGSM44BAEwggEeAoGBAL/wwml0NqxlQeeV6eIVvdVm4/RSWcFf
58yq1pU9WvJN6OXO1pOthtiX/qK4QEoJCGBWAVf3dWe4Hfc++Rt8T7H/WJEUyOqr
XtrYyGmrVG52cI6zgglaEHnjJkugJQwdW//hu7Yl5SJmNwnHoiYsb/QkiRvST3bL
uRngBPBlOji1AhUAmunBaKpMgKPiE0QK7inmUbySOasCgYAL6/1tPi88V/tgp6t5
SCQ8ZOgZqEYqQaJOP4dV8OXtJ0+mM5PugQHC95elQKU/oQ7VP6yiePyHisN1LQla
Pf2Bp2R0saxUSa6JND2DAbRw7IIrmjnV/I7mFGWOzu4fl+Xa2cxDZx71YjeJIlkQ
TLyo0lg/vaPaq9dbYEiwzC5XTgOBhAACgYAZrAX3TG+VfBcvLVBEmDKb7IPutrTZ
/UBdr/iim4+7Nnk4ulJcrNNyx7uJZSUHUdsn5xGzNQoKwB7LFKzWUGgOkstfXcjS
Md0rBD2FV474v1mmK4M5zB2m3UuBd7Qg0yFoZt+zwvim6ke09D9QuDpANgUwejEi
T06Oxbtce6McUg==
-----END PUBLIC KEY-----


同じことをpython
pycryptoだとPEMの出力をサポートしてない感じだったので、M2Cryptoでやってみた

# coding=utf-8
from M2Crypto import DSA, BIO


# DSAパラメータの作成
dsa = DSA.gen_params(1024)
f = BIO.File(open('dsa_param.pem', 'w'))
dsa.save_params_bio(f)

# 鍵の生成
dsa.gen_key()

# DSA秘密鍵を出力。暗号化無し
f = BIO.File(open('dsa_private.pem', 'w'))
dsa.save_key_bio(f, cipher=None)

# DSA秘密鍵を出力。des3で暗号化
f = BIO.File(open('dsa_private_des3.pem', 'w'))
dsa.save_key_bio(f, cipher='des_ede3_cbc', callback=lambda x: 'hogehogehogehoge')

# DSA公開鍵を出力
f = BIO.File(open('dsa_public.pem', 'w'))
dsa.save_pub_key_bio(f)


出力結果

dsa_param.pem

-----BEGIN DSA PARAMETERS-----
MIIBHgKBgQCcWO86lqNxxAxXbZ0nv6JL5kCHlEULcocWZNqKniTlEYNyKqnPs3AO
SP73ryUj/anZm0W62Jwsa45xmyKcUNjcNJFxIwDFr6TKQWFP+aD2/6z5DRZ5GVd8
FXGjaZ8MMBBqLzsvbhAj7mgqsLhIY61TM7Eu+MXI554LOIfwZ16towIVAPb5GcNB
r7fbCMo8sarnpn6VZKvHAoGAfDJ9JXaajeg7Q3pfvoPij8npHqrlzpMhHEIvW6uO
gbkhmuTXx+stq+PzYxfm3aGhfj7CgOC6bqRjhsIevCdAWfCVxHGiwWE7pMBvSkw4
p34Jt1Hgkft5YTbWo7EwlwIfC7UNSXQHkiSJ1gk8E/C8OlbUsbpC06sIHyIJm4Wd
b/o=
-----END DSA PARAMETERS-----

dsa_private.pem

-----BEGIN DSA PRIVATE KEY-----
MIIBugIBAAKBgQCcWO86lqNxxAxXbZ0nv6JL5kCHlEULcocWZNqKniTlEYNyKqnP
s3AOSP73ryUj/anZm0W62Jwsa45xmyKcUNjcNJFxIwDFr6TKQWFP+aD2/6z5DRZ5
GVd8FXGjaZ8MMBBqLzsvbhAj7mgqsLhIY61TM7Eu+MXI554LOIfwZ16towIVAPb5
GcNBr7fbCMo8sarnpn6VZKvHAoGAfDJ9JXaajeg7Q3pfvoPij8npHqrlzpMhHEIv
W6uOgbkhmuTXx+stq+PzYxfm3aGhfj7CgOC6bqRjhsIevCdAWfCVxHGiwWE7pMBv
Skw4p34Jt1Hgkft5YTbWo7EwlwIfC7UNSXQHkiSJ1gk8E/C8OlbUsbpC06sIHyIJ
m4Wdb/oCgYAS53XTRuaQmC1JY2dvNmVl8Y2HQuvmtlW/eRbrnafpaYVfipyqiwl2
1E0B56RyseLqkPgQIqD3F4bT2HWmLp2Tkw+eok66I79llzwEAtigZIebGV8OPe3l
zJDpXzIOJMr4xvrSDAtECz6r5H+IcmRTWqLNOCYO+Knn37llus8HQgIUIl2xMgbN
yjZl4MIkqFXerC54jNw=
-----END DSA PRIVATE KEY-----

dsa_private_des3.pem

-----BEGIN DSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CBC,F30337BCE0A70314

mW3VFKcZlNjKwGZt8PLmqCPGEmmiA61DxwBLq45BUNYaHq4xNYcCIwqcK0XsuFgu
Dq/717p8oVAKTLb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