dpapi.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:SoCFoundationFlow 作者: mattaw 项目源码 文件源码
def dpapi_encrypt_data(self, input_bytes, entropy = extra_entropy):
    '''
    Encrypts data and returns byte string

    :param input_bytes: The data to be encrypted
    :type input_bytes: String or Bytes
    :param entropy: Extra entropy to add to the encryption process (optional)
    :type entropy: String or Bytes
    '''
    if not isinstance(input_bytes, bytes) or not isinstance(entropy, bytes):
        self.fatal('The inputs to dpapi must be bytes')
    buffer_in      = c_buffer(input_bytes, len(input_bytes))
    buffer_entropy = c_buffer(entropy, len(entropy))
    blob_in        = DATA_BLOB(len(input_bytes), buffer_in)
    blob_entropy   = DATA_BLOB(len(entropy), buffer_entropy)
    blob_out       = DATA_BLOB()

    if CryptProtectData(byref(blob_in), 'python_data', byref(blob_entropy), 
        None, None, CRYPTPROTECT_UI_FORBIDDEN, byref(blob_out)):
        return get_data(blob_out)
    else:
        self.fatal('Failed to decrypt data')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号