-1
그래서 내가 암호화 및 암호 해독에 내 파이썬 능력을 향상하기로 결정하고 다음 실행하는 파이썬 프로그램을 작성하는 시도 :DES, RSA 암호화 및 암호 해독
- 는 1024 비트 개인 키와 키 공개를 생성을
- 암호화 DES 알고리즘
- 을 파일에 저장
- 저장 RSA 등을 통해
- 암호화하는 공개 키를 사용하여 파일에 공개 키 암호화 된 개인 키와 개인 키 gorithm, 파일
나는 오류가 계속 :
Traceback (most recent call last):
File "C:\Users\john\Desktop\python\E&D.py", line 10, in <module>
pr = RSA.importKey(open('mykey.pem', 'r'))
File "C:\Python27\lib\site-packages\Crypto\PublicKey\RSA.py", line 678, in importKey
if bord(externKey[0])==0x30:
IndexError: string index out of range
내 코드 :
import Crypto
from Crypto.PublicKey import RSA
from Crypto.Cipher import DES
# Generate Private Key
private = RSA.generate(1024)
m = open('mykey.pem','w')
m.write(private.exportKey('PEM'))
#Get public key
public = private.publickey()
pr = RSA.importKey(open('mykey.pem', 'r'))
#DES encryption
password= ''
des= DES.new(password,DES.MODE_ECB)
des_cipher= des.encrypt(pr)
f = open('privatekey.dat','w')
l = open('publickey.dat','w')
s=open('encrypted.dat','w')
w = open('encrypt.dat', 'r')
war = w.read()
f.write(des_cipher)
l.write(public)
#RSA encryption
enc_data = public.encrypt(war)
s.write(enc_data)
f.close()
l.close()
s.close()
w.close()
m.close()