我正在尝试加密Django中的值,但我总是遇到数据库错误。我想它不想在数据库中存储8位字符串。有办法吗?我在本地机器上使用SQlite,在生产中使用postgreSQL。另外,这是我的代码
def set_message(self, raw_message):
last_four = raw_message[len(raw_message)-4:len(raw_message)]
rest = '*'
for n in range(0,len(raw_message)-5):
rest=rest+'*'
self.message_string = rest+str(last_four)
extra_words = len(raw_message) % 8 #since Strings for DES must be a multiple of 8 in length
add_words_length = 8 - extra_words
for x in range(0,add_words_length):
raw_message = raw_message + 'X'
obj=DES.new('abcdefgh', DES.MODE_ECB)
encrypt_raw_message=obj.encrypt(raw_message)
self.message = encrypt_raw_message
self.save()