在Python中使用DPAPI?

有没有办法在Windows XP上使用Python的DPAPI(数据保护应用程序编程接口)?

如果有可用的模块,我宁愿使用现有的模块。 不幸的是,我一直无法find与谷歌或堆栈溢出方式。

编辑:我已经采取了由“dF”指向的示例代码,并将其调整到一个独立的库,可以简单地在高层次使用用户模式下使用DPAPIencryption和解密。 只需调用返回encryptionstring的dpapi.cryptData(text_to_encrypt)或返回纯文本的reverse decryptData(encrypted_data_string)即可。 这是图书馆:

# DPAPI access library # This file uses code originally created by Crusher Joe: # http://article.gmane.org/gmane.comp.python.ctypes/420 # from ctypes import * from ctypes.wintypes import DWORD LocalFree = windll.kernel32.LocalFree memcpy = cdll.msvcrt.memcpy CryptProtectData = windll.crypt32.CryptProtectData CryptUnprotectData = windll.crypt32.CryptUnprotectData CRYPTPROTECT_UI_FORBIDDEN = 0x01 extraEntropy = "cl;ad13 \0al;323kjd #(adl;k$#ajsd" class DATA_BLOB(Structure): _fields_ = [("cbData", DWORD), ("pbData", POINTER(c_char))] def getData(blobOut): cbData = int(blobOut.cbData) pbData = blobOut.pbData buffer = c_buffer(cbData) memcpy(buffer, pbData, cbData) LocalFree(pbData); return buffer.raw def Win32CryptProtectData(plainText, entropy): bufferIn = c_buffer(plainText, len(plainText)) blobIn = DATA_BLOB(len(plainText), bufferIn) bufferEntropy = c_buffer(entropy, len(entropy)) blobEntropy = DATA_BLOB(len(entropy), bufferEntropy) blobOut = DATA_BLOB() if CryptProtectData(byref(blobIn), u"python_data", byref(blobEntropy), None, None, CRYPTPROTECT_UI_FORBIDDEN, byref(blobOut)): return getData(blobOut) else: return "" def Win32CryptUnprotectData(cipherText, entropy): bufferIn = c_buffer(cipherText, len(cipherText)) blobIn = DATA_BLOB(len(cipherText), bufferIn) bufferEntropy = c_buffer(entropy, len(entropy)) blobEntropy = DATA_BLOB(len(entropy), bufferEntropy) blobOut = DATA_BLOB() if CryptUnprotectData(byref(blobIn), None, byref(blobEntropy), None, None, CRYPTPROTECT_UI_FORBIDDEN, byref(blobOut)): return getData(blobOut) else: return "" def cryptData(text): return Win32CryptProtectData(text, extraEntropy) def decryptData(cipher_text): return Win32CryptUnprotectData(cipher_text, extraEntropy) 

Solutions Collecting From Web of "在Python中使用DPAPI?"