python加密解密字符串_Python字符串加密解密方法总结

1.

1.

最简单的方法是用

base64:

2.

3.

import base64

4.

5.

s1 = base64.encodestring('hello world')

6.

s2 = base64.decodestring(s1)

7.

print s1,s2

8.

9.

# aGVsbG8gd29ybGQ=\n

10.

# hello world

11.

12.

:

这是最简单的方法了,

但是不够保险,

因为如果别人拿到你的密文,

也可以自己解密来得到明文;

不过可以把密文字符串进行处理,

如字母转换成数字或是特殊字符等,

自己解密的时候在替换回去在

进行

base64.decodestring

,这样要安全很多。

13.

14.

15.

16.

17.2.

第二种方法是使用

win32com.client

18.

19.import win32com.client

20.def encrypt(key,content):

# key:

密钥

,content:

明文

21. EncryptedData = win32com.client.Dispatch('CAPICOM.EncryptedData')

22. Encrypted

你可能感兴趣的:(python加密解密字符串)