hussaintamboli / py-cidecrypt Goto Github PK
View Code? Open in Web Editor NEWDecrypt what was encrypted in CodeIgniter using Encrypt library.
Decrypt what was encrypted in CodeIgniter using Encrypt library.
The code didn't work out of the box for me..
So I'll leave this here for the next poor soul who has to dig into an old codeigniter database with Python:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import hashlib
import base64
import mcrypt # Downloaded from https://pypi.python.org/pypi/python-mcrypt
# or http://labix.org/python-mcrypt.
# If the installation gives error - "mycrypt.h file not found" then
# Install libmcrypt or libmcrypt-dev . See the document in python help(mcrypt)
class Decrypt:
def __init__(self, key=''):
self.key = key
self.SUCCESS, self.FAILED = True, False
self.KEY_SIZE = 32
self.BLOCK_SIZE = 32
def getKey(self, key):
md5Key = hashlib.md5()
md5Key.update(key)
return md5Key.hexdigest()
def getBase64Decode(self, encString):
b64DecString = base64.b64decode(encString)
return b64DecString
def hashMethod(self, key):
hashStr = ''
try:
hashStr = hashlib.sha1(key).hexdigest()
except Exception as e:
return self.FAILED
return hashStr
def removeCipherNoise(self, string, key):
keyHash = self.hashMethod(key)
keylen = len(keyHash)
stri = ''.encode('iso-8859-1')
i, j = 0, 0
length = len(string)
while i < length:
if j >= keylen:
j = 0
temp = ord(string[i]) - ord(keyHash[j])
if temp < 0:
temp = temp + 256
stri += chr(temp)
i += 1
j += 1
return stri
def mcryptDecode(self, string, key):
string = self.removeCipherNoise(string, key)
initSize = 32
initVect = string[0:initSize]
string = string[initSize:]
decoded = self.mcryptDecryption(key, initVect, string)
if decoded == self.FAILED:
return self.FAILED
return decoded.rstrip('\x00')
def decode(self, string):
if not self.key:
return self.FAILED
dec = self.getBase64Decode(string)
decoded = self.mcryptDecode(dec, self.key)
if decoded == self.FAILED:
return self.FAILED
return decoded
def mcryptDecryption(self, key, iv, data):
try:
m = mcrypt.MCRYPT('rijndael-256', 'cbc')
m.init(key, iv)
decrypted = m.decrypt(data)
except Exception as e:
return self.FAILED
return decrypted
text = 'ENCRYPTED_TEXT'
dec = Decrypt(key='YOUR_KEY')
print dec.decode(text)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.