Package: blowcurve
Blowcurve Encryption LibraryRepository:https://www.github.com/origamizyt/blowcurveSimple library for Blowfish / ECC encryption and digital signatures.InstallationThis library is available on PyPI.pip install blowcurveOr you could also install from source code.python setup.py installUsageTheBlowcurveclass in package root provides all usage.
You can initialize it without any parameters to generate random keys: (In fact, this is the only way to create instances.)>>>fromblowcurveimportBlowcurve>>>bc1=Blowcurve()>>>bc2=Blowcurve()Theexportmethod allows you to export the key as DER hex string:>>>bc1.export()'3059301306072a8648ce3d020106082a8648ce3d030107034200041c873634bf4b14d555800e33482971ca55e5780e8c109c817adf185919060e414857851ee2bdff18cd76510b80c79f3b11380810e2be9a876765722ed9c7f465'Theloadmethod performs ecdh key exchange with remote services:>>>bc1.load(bc2.export())>>>bc2.load(bc1.export())No error means key exchange was successful.After key exchange, thesignandencryptmethods are enabled:>>>signature=bc1.sign(b'data')>>>bc2.verify(b'data',signature)True>>>data=b'mymessage'>>>bc2.decrypt(bc1.encrypt(data))b'message'If no remote key was provided, aMissingRemoteKeyexception will be raised:>>>Blowcurve().encrypt(b'')Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"__init__.py",line41,inencryptephemeral,key=self._pair.ephemeral()File"keys.py",line94,inephemeralraiseMissingRemoteKeyblowcurve.keys.MissingRemoteKey:remotekeynotloadedyet.>>>Blowcurve().verify(b'',b'')Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"__init__.py",line38,inverifyreturnself._pair.verify(data,signature)File"keys.py",line109,inverifyraiseMissingRemoteKeyblowcurve.keys.MissingRemoteKey:remotekeynotloadedyet.Thekeysmodule has API for basic signing and ecdh.>>>fromblowcurve.keysimportECKeys>>>k1=ECKeys()>>>k2=ECKeys()>>>k1.load(k2.export())>>>k2.load(k1.export())>>>k1.secret()==k2.secret()True>>>k2.verify(b'data',k1.sign(b'data'))TrueThecryptmodule has API for encryption and padding.>>>fromblowcurveimportcrypt>>>crypt.pkcs5_pad(b'data',8)b'data\x04\x04\x04\x04'>>>crypt.pkcs5_pad(b'mymessage',16)b'mymessage\x07\x07\x07\x07\x07\x07\x07'>>>crypt.pkcs5_unpad(b'data\x04\x04\x04\x04')b'data'>>>crypt.pkcs5_unpad(b'incorrect\x01\x02\x03')Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"crypt.py",line41,inpkcs5_unpadraiseIncorrectPaddingblowcurve.crypt.IncorrectPadding:incorrectpadding>>>data=crypt.encrypt(b'mykey',b'hello, world!')>>>crypt.decrypt(b'mykey',data)b'hello, world!'>>>crypt.decrypt(b'other',data)Traceback(mostrecentcalllast):File"<stdin>",line1,in<module>File"crypt.py",line71,indecryptreturnpkcs5_unpad(cipher.decrypt(data))File"crypt.py",line41,inpkcs5_unpadraiseIncorrectPaddingblowcurve.crypt.IncorrectPadding:incorrectpaddingThe cause of the exception above is because the incorrect key results in incorrect decrypted data, therefore causing an incorrect padding. (There is chance that this exception won't occur, but the result will still be malformed.)TestingThetest.pyfile contains unittest test cases:$ python -m unittest --verbose blowcurve.test
testEncrypt (blowcurve.test.BlowcurveTestCase) ... ok
testSign (blowcurve.test.BlowcurveTestCase) ... ok
testEncrypt (blowcurve.test.CryptTestCase) ... ok
testPad (blowcurve.test.CryptTestCase) ... ok
testNoRemoteKey (blowcurve.test.KeysTestCase) ... ok
testSecret (blowcurve.test.KeysTestCase) ... ok
testSign (blowcurve.test.KeysTestCase) ... ok

----------------------------------------------------------------------
Ran 7 tests in 0.179s

OK