解码散列字符串
Decoding hashed strings
我已经成功编码了一些用户输入。但是我无法解码。
这是我的代码:
from PyQt4 import QtGui, QtCore
import sys, os
from PyQt4.Qt import SIGNAL, SLOT, QMainWindow, qApp, QUrl, QImage,\
QStringListModel
import hashlib
import base64
class Dialog_01(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow,self).__init__()
myQWidget = QtGui.QWidget()
myBoxLayout = QtGui.QVBoxLayout()
myQWidget.setLayout(myBoxLayout)
self.setCentralWidget(myQWidget)
self.line = QtGui.QLineEdit(self)
self.line.setObjectName("host")
savebutton = QtGui.QPushButton("Print")
savebutton.setMinimumSize(35,30)
savebutton.clicked.connect(self.printtext)
myBoxLayout.addWidget(savebutton)
def printtext(self):
shost = self.line.text()
#shost = "Hello"
#print(self.ComboBox.currentText())
self.md = hashlib.md5()
self.md.update(shost.encode())
str1 = (self.md.hexdigest())
print(str1)
str2 = codecs.decode(s, '5d41402abc4b2a76b9719d911017c592')
print(str2)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dialog_1 = Dialog_01()
dialog_1.show()
dialog_1.resize(480,320)
sys.exit(app.exec_())
我这里要的是解码加密后的字符串(str1
).
您不能对 encrypt/decrypt 个字符串使用安全哈希函数。
事实上,哈希算法是专门设计的,因此它们的输出不能被解密——这就是它们安全的原因!哈希通常用于检查传输数据的真实性。如果当前数据的哈希值与原始数据的哈希值匹配,您可以确信它们是相同的数据。
Python和Qt中都没有内置encryption/decryption,所以如果你想要,你需要使用第三方库,比如simple-crypt or pycrypto .
另一方面,如果您想要的只是非安全混淆,请查看此 SO 问题中的一些建议:
- Simple way to encode a string according to a password?
我已经成功编码了一些用户输入。但是我无法解码。
这是我的代码:
from PyQt4 import QtGui, QtCore
import sys, os
from PyQt4.Qt import SIGNAL, SLOT, QMainWindow, qApp, QUrl, QImage,\
QStringListModel
import hashlib
import base64
class Dialog_01(QtGui.QMainWindow):
def __init__(self):
super(QtGui.QMainWindow,self).__init__()
myQWidget = QtGui.QWidget()
myBoxLayout = QtGui.QVBoxLayout()
myQWidget.setLayout(myBoxLayout)
self.setCentralWidget(myQWidget)
self.line = QtGui.QLineEdit(self)
self.line.setObjectName("host")
savebutton = QtGui.QPushButton("Print")
savebutton.setMinimumSize(35,30)
savebutton.clicked.connect(self.printtext)
myBoxLayout.addWidget(savebutton)
def printtext(self):
shost = self.line.text()
#shost = "Hello"
#print(self.ComboBox.currentText())
self.md = hashlib.md5()
self.md.update(shost.encode())
str1 = (self.md.hexdigest())
print(str1)
str2 = codecs.decode(s, '5d41402abc4b2a76b9719d911017c592')
print(str2)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
dialog_1 = Dialog_01()
dialog_1.show()
dialog_1.resize(480,320)
sys.exit(app.exec_())
我这里要的是解码加密后的字符串(str1
).
您不能对 encrypt/decrypt 个字符串使用安全哈希函数。
事实上,哈希算法是专门设计的,因此它们的输出不能被解密——这就是它们安全的原因!哈希通常用于检查传输数据的真实性。如果当前数据的哈希值与原始数据的哈希值匹配,您可以确信它们是相同的数据。
Python和Qt中都没有内置encryption/decryption,所以如果你想要,你需要使用第三方库,比如simple-crypt or pycrypto .
另一方面,如果您想要的只是非安全混淆,请查看此 SO 问题中的一些建议:
- Simple way to encode a string according to a password?