mirror of
https://github.com/autistic-symposium/sec-pentesting-toolkit.git
synced 2025-05-02 14:56:10 -04:00
crypto modules
This commit is contained in:
parent
f211c1cbab
commit
5fcb5a5cb9
28 changed files with 122 additions and 7 deletions
44
Cryptography/Public_Key/RSA.py
Normal file
44
Cryptography/Public_Key/RSA.py
Normal file
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto import Random
|
||||
|
||||
|
||||
def gen_key(nbits=1024):
|
||||
random_generator = Random.new().read
|
||||
key = RSA.generate(nbits, random_generator)
|
||||
return key
|
||||
|
||||
def check_key(key):
|
||||
print key.can_encrypt()
|
||||
print key.can_sign()
|
||||
print key.has_private()
|
||||
|
||||
|
||||
def get_pubk(key):
|
||||
return key.publickey()
|
||||
|
||||
|
||||
def encrypt(public_key, text, random):
|
||||
return public_key.encrypt(text, random)
|
||||
|
||||
|
||||
def decrypt(data):
|
||||
return key.decrypt(enc_data)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
key = gen_key()
|
||||
|
||||
check_key(key)
|
||||
|
||||
public_key = get_pubk(key)
|
||||
|
||||
text = 'abcdefgh'
|
||||
enc_data = encrypt(public_key, text, random=32)
|
||||
print enc_data
|
||||
|
||||
dec_data = decrypt(enc_data)
|
||||
print dec_data
|
||||
|
16
Cryptography/Public_Key/RSA_sign.py
Normal file
16
Cryptography/Public_Key/RSA_sign.py
Normal file
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
|
||||
|
||||
from Crypto.Hash import SHA256
|
||||
from Crypto.PublicKey import RSA
|
||||
from Crypto import Random
|
||||
|
||||
key = RSA.generate(1024)
|
||||
text = 'abcdefgh'
|
||||
|
||||
hash = SHA256.new(text).digest()
|
||||
print hash
|
||||
|
||||
signature = key.sign(hash, '')
|
||||
print signature
|
Loading…
Add table
Add a link
Reference in a new issue