[cryptohack] Privacy-Enhanced Mail, CERTainly not, SSH Keys

ShinboTinBBO·2025년 2월 23일

cryptography

목록 보기
9/10

GoF입니다. (Greatest of Feburary) 하핫

암튼 이번까지는 cryptohack의 general 부분의 간단한 데이터 포멧에 관련한 문제여서, 나중에 이러한 데이터 포멧을 만나면 이러한 코드를 사용하자는 느낌으로 간단히 정리해보겠습니다.

Privacy-Enhanced Mail?

주어진 개인키의 d를 출력해보자.
주어진 파일은 pem 확장자를 가진다.

from Crypto.PublicKey import RSA

file_path = 'privacy_enhanced_mail.pem'
with open(file_path,'rb') as key_file:
    key = RSA.importKey(key_file.read())
    print(key.d)

CERTainly not

der 포멧에서 모듈로 뽑기

from Crypto.PublicKey import RSA

file_path = '2048b-rsa-example-cert.der'
with open(file_path, 'rb') as key_file:
    key = RSA.importKey(key_file.read())
    print(key.n)

SSH Keys

SSH에서 사용되는 키에서 모듈로 n 뽑기

from Crypto.PublicKey import RSA

file_path = 'SSH_keys/bruce_rsa.pub'
key_file = RSA.importKey(open(file_path, 'rb').read())

print(key_file.n)

보시다시피, pem, der, pub 포멧 모두, 동일한 코드를 통해서 파싱이 가능한 것을 확인할 수 있다.

profile
지상 최강의 해적

0개의 댓글