Giter VIP home page Giter VIP logo

objcrypt's Introduction

objcrypt

easily encrypt and decrypt python object and JSON objects with AES CBC 32 Block Encryption

planning on adding more encryption algos

installation

pip install objcrypt

or

python3 setup.py install

usage

import objcrypt, json

crypter = objcrypt.Crypter('key')
dictionary = {
  'test': 'test value'
}
encrypted_dict = crypter.encrypt_object(dictionary)

# encrypted_dict now has encrypted values

json_dict = json.loads(dictionary)
enc_json = crypter.encrypt_json(json_dict)

# enc_json is now encrypted

dec_dict = crypter.decrypt_object(encrypted_dict)

# decoded now

dec_json = crypter.decrypt_json(enc_json)

# decoded json object now

objcrypt's People

Contributors

frenchie0x4ff avatar m4cs avatar tam-nguyen-vn avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

objcrypt's Issues

TypeError: Object type <class 'str'> cannot be passed to C code

When using objcrypt with python3.8 I get the following error when running Crypter('key').encrypt_object(data).

Traceback (most recent call last):
  File ".../test.py", line 7, in <module>
    encrypted_dict = cr.encrypt_object(dictionary)
  File "/usr/lib/python3.8/site-packages/objcrypt/crypter.py", line 20, in encrypt_object
    new_obj[key] = base64.b64encode(iv + cipher.encrypt(raw_value)).decode('utf-8')
  File "/usr/lib/python3.8/site-packages/Crypto/Cipher/_mode_cbc.py", line 178, in encrypt
    c_uint8_ptr(plaintext),
  File "/usr/lib/python3.8/site-packages/Crypto/Util/_raw_api.py", line 144, in c_uint8_ptr
    raise TypeError("Object type %s cannot be passed to C code" % type(data))
TypeError: Object type <class 'str'> cannot be passed to C code

Changing

new_obj[obj_key] = base64.b64encode(iv + cipher.encrypt(raw_value)).decode('utf-8')

to

new_obj[obj_key] = base64.b64encode(iv + cipher.encrypt(str.encode(raw_value))).decode('utf-8')

in the _encrypt_object method fixed the problem for me - as I am not an encryption expert I'm not sure why it fixed the problem (this solution was inspired by this post).

In Documentation

json_dict = json.loads(dictionary)

Change loads method to dump i.e json.dump(dictionary)

Because loads convert JSON to Python object what we need here is reverse convert Python object to JSON object .It'll be done by json.dump(Python_object) method.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.