With the configuration defaults:
from cryptopyutils.privatekey import PrivateKey
# create the PrivateKey object with the configuration defaults
privk = PrivateKey()or with your own configuration:
from cryptopyutils.privatekey import PrivateKey
from cryptopyutils.config import PrivateKeyCconfig
myconfig = PrivateKeyCconfig()
# you can then modify your configuration
# create the PrivateKey object with your configuration
privk = PrivateKey(config=myconfig)privk.gen()
# alternative: generate an ED25519 key
# privk.gen("ED25519")filepath = "/tmp/myexample.com.pem"
privk.save(filepath)
>> TrueIf saved it returns True, otherwise False.
filepath = "/tmp/myexample.com.pem"
privk.load(filepath)print(privk.keytext)message = b'my message to sign'
signature = privk.sign(message)
# print the signed message
print(signature)Example of output:
>>b'638QWTOjdT712NOmpPi+nLBGdZ6zQ64+ZNQcOTSpyZDQv7k3mO4piHNNVHxz7L3scQgThcp1QBQR7fyrAep7Ys2ozB6bAvCI6wUSF8achgTt69HY...'RSA is the encryption / decryption technique supported by cryptopyutils.
This example assumes you already have loaded your private key.
#load the cipher text (this case is invalid)
ciphertext = b'e83JOPUT7e6syGGoJeAyU128cde0Ck4V7/lwo+0OHu/SXB2N/e5/JEdTdvbUY+j8...'
#decrypt
plaintext = privk.decrypt(ciphertext)
#print the decrypted message
print(ciphertext)
>> b'my message to encrypt'