Skip to content

Instantly share code, notes, and snippets.

@bholagabbar
Created December 17, 2017 07:30
Show Gist options
  • Save bholagabbar/53732208d8f886db3ec8a69ddad5be13 to your computer and use it in GitHub Desktop.
Save bholagabbar/53732208d8f886db3ec8a69ddad5be13 to your computer and use it in GitHub Desktop.
ECC Encryption Decryption
import seccure
# Using ECC Encryption Decrpytion
private_key = '123tadfg1wt1qdg123512er2'.encode('utf-8')
public_key = 'BCGB&[gT#hf6?b*63nSaX+L-0'.encode('utf-8')
message = 'This is a secret message'.encode('utf-8')
print(str(message), '\n')
encrypted = seccure.encrypt(message, public_key)
print('Encrypted:\n{}\n'.format(str(encrypted)))
"""
Can mobile devs integrate THE DECRPYTION PART ONLY (modeled in pythob below)
with the same public key as provided above, test it with the message
and compare the outputs?
* Android Snippet : See code from btnDecrypt.setOnClickListener(new View.OnClickListener() in the Question below
https://stackoverflow.com/questions/46306052/elliptic-curve-cryptography-ecc-encrypt-decrypt-using-bouncy-castle-in-java
* iOS: https://github.com/agens-no/EllipticCurveKeyPair
"""
decrypted = seccure.decrypt(encrypted, private_key)
print('Decrypted:\n{}'.format(str(decrypted)))
# 'b prefix denotes that the string is encoded in utf-8 or more correctly, they are bytes
"""OUTPUT
b'This is a secret message'
Encrypted:
b'\x01e\xffA\x11\xf4\xe7\xed\x1d\r\xcb\x82\xcel\x1c\xc47\xd7M\x1f\xed\xa2\xaaG\xa0(\r@\xc0\x83\xe2w\x81\xd2\xa2\xfe\xdb\x08\xbf\x7f\x82\xcf\xaa=\xc5Q\x8f\x9cR\x86\xbf`Q\xfd\xff'
Decrypted:
b'This is a secret message'
"""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment