에서 내가 좋아하는 CI에서 그들을 인코딩하여 로그인 암호와 같은 자격 증명을 저장했다. CI의 디코딩을 관찰하여 그래서, 나는 Python으로 내 자신의 암호 해독 모듈을 작성했습니다 - CodeIgniter의에서 인코딩하고 디코딩 파이썬
// Like CI get_key
def getKey(self, key):
self.log.info("In getKey method with key : %s"%key)
md5Key = hashlib.md5()
md5Key.update(key)
return md5Key.hexdigest()
// Like CI base64_decode
def getBase64Decode(self, encString):
self.log.info("In getBase64Decode.")
b64DecString = base64.b64decode(encString)
return b64DecString
// Like CI _xor_decode
def xorDecode(self, string, key):
self.log.info("In xorDecode method with string : %s and key : %s"%(string, key))
mString = self.xorMerge(string, key)
if mString == self.FAILED:
self.log.info("xorMerge Failed!")
return self.FAILED
self.log.info("xor Merge returned %s"%mString)
dec = ''
for (x, y) in izip(mString[1:], cycle(mString)):
dec += ''.join(chr(ord(x)^ord(y)))
// Like CI _xor_merge
def xorMerge(self, string, key):
self.log.info("In xorMerge method. with string : %s and key : %s"%(string, key))
hashString = self.hashMethod(key)
if hashString == self.FAILED:
self.log.info("hasMethod failed!")
return self.FAILED
self.log.info("hash method retured : %s"%hashString)
xored = ''
for (x, y) in izip(string, cycle(hashString)):
xored += ''.join(chr(ord(x)^ord(y)))
// Like CI hash
def hashMethod(self, key):
self.log.info("In hash method with key : %s"%key)
hashStr = ''
try:
hashStr = hashlib.sha1(key).hexdigest()
except Exception, e:
self.log.info("Exception in sha1 %s"%str(e))
return self.FAILED
return hashStr
// Like CI decode
def decode(self, string):
self.log.info("In decode method. Decoding string : %s"%string)
securitySection = "security"
keyItem = "key"
key = self.config.get(securitySection, keyItem)
if not key:
self.log.info("Key Invalid")
return self.FAILED
key = self.getKey(key)
self.log.info("Encrypted key : %s"%key)
dec = self.getBase64Decode(string)
self.log.info("b64decoded string : %s"%dec)
xorDec = self.xorDecode(dec, key)
if xorDec == self.FAILED:
self.log.info("Decoding failed!")
return self.FAILED
self.log.info("Decoded string: %s"%xorDec)
return xorDec
위의 방법의 모든
는 암호 해독 모듈의 암호 해독 클래스로 작성됩니다.그래서 암호화 된 문자열을 메서드에 전달하면 실제 자격 증명이 아닌 이상한 유니 코드 문자열이 표시됩니다. 내가 CI로 확인했을 때 위의 코드에서 xorMerge
을 입력해도 CI에있는 _xor_merge
과 같은 출력이 나오지 않습니다. 내가 도대체 뭘 잘못하고있는 겁니까?