當前位置: 首頁>>代碼示例>>Python>>正文


Python KDF.PBKDF2屬性代碼示例

本文整理匯總了Python中Cryptodome.Protocol.KDF.PBKDF2屬性的典型用法代碼示例。如果您正苦於以下問題:Python KDF.PBKDF2屬性的具體用法?Python KDF.PBKDF2怎麽用?Python KDF.PBKDF2使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在Cryptodome.Protocol.KDF的用法示例。


在下文中一共展示了KDF.PBKDF2屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test2

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def test2(self):
        """From draft-josefsson-scrypt-kdf-01, Chapter 10"""

        output_1 = t2b("""
        55 ac 04 6e 56 e3 08 9f ec 16 91 c2 25 44 b6 05
        f9 41 85 21 6d de 04 65 e6 8b 9d 57 c2 0d ac bc
        49 ca 9c cc f1 79 b6 45 99 16 64 b3 9d 77 ef 31
        7c 71 b8 45 b1 e3 0b d5 09 11 20 41 d3 a1 97 83
        """)

        output_2 = t2b("""
        4d dc d8 f6 0b 98 be 21 83 0c ee 5e f2 27 01 f9
        64 1a 44 18 d0 4c 04 14 ae ff 08 87 6b 34 ab 56
        a1 d4 25 a1 22 58 33 54 9a db 84 1b 51 c9 b3 17
        6a 27 2b de bb a1 d0 78 47 8f 62 b3 97 f3 3c 8d
        """)

        prf_hmac_sha256 = lambda p, s: HMAC.new(p, s, SHA256).digest()

        output = PBKDF2(b("passwd"), b("salt"), 64, 1, prf=prf_hmac_sha256)
        self.assertEqual(output, output_1)

        output = PBKDF2(b("Password"), b("NaCl"), 64, 80000, prf=prf_hmac_sha256)
        self.assertEqual(output, output_2) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:26,代碼來源:test_KDF.py

示例2: kdf

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def kdf(password,salt):
    return KDF.PBKDF2(password, salt, dkLen=32, count=2000) 
開發者ID:keylime,項目名稱:keylime,代碼行數:4,代碼來源:cryptodome.py

示例3: derive_auth_key

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def derive_auth_key(secret, password=None, url=None):
    if password is None:
        return hkdf(64, secret, info=b'authentication')
    else:
        return PBKDF2(password.encode('utf8'), url.encode('utf8'), 64, 100,
                      lambda x, y: hmac.new(x, y, sha256).digest()) 
開發者ID:nneonneo,項目名稱:ffsend,代碼行數:8,代碼來源:ffsend.py

示例4: string_to_key

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def string_to_key(cls, string, salt, params):
        (iterations,) = unpack('>L', params or b'\x00\x00\x10\x00')
        prf = lambda p, s: HMAC.new(p, s, SHA).digest()
        seed = PBKDF2(string, salt, cls.seedsize, iterations, prf)
        tkey = cls.random_to_key(seed)
        return cls.derive(tkey, b'kerberos') 
開發者ID:Coalfire-Research,項目名稱:Slackor,代碼行數:8,代碼來源:crypto.py

示例5: test1

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def test1(self):
        # Test only for HMAC-SHA1 as PRF

        def prf(p,s):
            return HMAC.new(p,s,SHA1).digest()

        for i in range(len(self._testData)):
            v = self._testData[i]
            res  = PBKDF2(v[0], t2b(v[1]), v[2], v[3])
            res2 = PBKDF2(v[0], t2b(v[1]), v[2], v[3], prf)
            self.assertEqual(res, t2b(v[4]))
            self.assertEqual(res, res2) 
開發者ID:haynieresearch,項目名稱:jarvis,代碼行數:14,代碼來源:test_KDF.py

示例6: test1

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def test1(self):
        # Test only for HMAC-SHA1 as PRF

        def prf(p,s):
            return HMAC.new(p,s,SHA1).digest()

        for i in xrange(len(self._testData)):
            v = self._testData[i]
            res  = PBKDF2(v[0], t2b(v[1]), v[2], v[3])
            res2 = PBKDF2(v[0], t2b(v[1]), v[2], v[3], prf)
            self.assertEqual(res, t2b(v[4]))
            self.assertEqual(res, res2) 
開發者ID:mchristopher,項目名稱:PokemonGo-DesktopMap,代碼行數:14,代碼來源:test_KDF.py

示例7: __init__

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def __init__(self, profile_path, browser_name=None, cache_path=None, version=None, timezone=None,
                 parsed_artifacts=None, parsed_storage=None, storage=None, installed_extensions=None, artifacts_counts=None, artifacts_display=None,
                 available_decrypts=None, preferences=None):
        WebBrowser.__init__(self, profile_path, browser_name=browser_name, cache_path=cache_path, version=version,
                            timezone=timezone, parsed_artifacts=parsed_artifacts, parsed_storage=parsed_storage,
                            artifacts_counts=artifacts_counts,
                            artifacts_display=artifacts_display, preferences=preferences)
        self.profile_path = profile_path
        self.browser_name = "Chrome"
        self.cache_path = cache_path
        self.timezone = timezone
        self.installed_extensions = installed_extensions
        self.cached_key = None
        self.available_decrypts = available_decrypts
        self.storage = storage
        self.preferences = preferences

        if self.version is None:
            self.version = []

        if self.structure is None:
            self.structure = {}

        if self.parsed_artifacts is None:
            self.parsed_artifacts = []

        if self.parsed_storage is None:
            self.parsed_storage = []

        if self.installed_extensions is None:
            self.installed_extensions = []

        if self.preferences is None:
            self.preferences = []

        if self.artifacts_counts is None:
            self.artifacts_counts = {}

        if self.storage is None:
            self.storage = {}

        if self.artifacts_display is None:
            self.artifacts_display = {}

        if self.available_decrypts is None:
            self.available_decrypts = {'windows': 0, 'mac': 0, 'linux': 0}

        if self.available_decrypts['windows'] == 1:
            import win32crypt

        if self.available_decrypts['mac'] == 1:
            import keyring
            from Cryptodome.Cipher import AES
            from Cryptodome.Protocol.KDF import PBKDF2

        if self.available_decrypts['linux'] == 1:
            from Cryptodome.Cipher import AES
            from Cryptodome.Protocol.KDF import PBKDF2 
開發者ID:obsidianforensics,項目名稱:hindsight,代碼行數:60,代碼來源:chrome.py

示例8: decrypt_cookie

# 需要導入模塊: from Cryptodome.Protocol import KDF [as 別名]
# 或者: from Cryptodome.Protocol.KDF import PBKDF2 [as 別名]
def decrypt_cookie(self, encrypted_value):
        """Decryption based on work by Nathan Henrie and Jordan Wright as well as Chromium source:
         - Mac/Linux: http://n8henrie.com/2014/05/decrypt-chrome-cookies-with-python/
         - Windows: https://gist.github.com/jordan-wright/5770442#file-chrome_extract-py
         - Relevant Chromium source code: http://src.chromium.org/viewvc/chrome/trunk/src/components/os_crypt/
         """
        salt = b'saltysalt'
        iv = b' ' * 16
        length = 16

        def chrome_decrypt(encrypted, key=None):
            # Encrypted cookies should be prefixed with 'v10' according to the
            # Chromium code. Strip it off.
            encrypted = encrypted[3:]

            # Strip padding by taking off number indicated by padding
            # eg if last is '\x0e' then ord('\x0e') == 14, so take off 14.
            def clean(x):
                return x[:-ord(x[-1])]

            cipher = AES.new(key, AES.MODE_CBC, IV=iv)
            decrypted = cipher.decrypt(encrypted)

            return clean(decrypted)

        decrypted_value = "<error>"
        if encrypted_value is not None:
            if len(encrypted_value) >= 2:
                # If running Chrome on Windows
                if sys.platform == 'win32' and self.available_decrypts['windows'] is 1:
                    try:
                        decrypted_value = win32crypt.CryptUnprotectData(encrypted_value, None, None, None, 0)[1]
                    except:
                        decrypted_value = "<encrypted>"
                # If running Chrome on OSX
                elif sys.platform == 'darwin' and self.available_decrypts['mac'] is 1:
                    try:
                        if not self.cached_key:
                            my_pass = keyring.get_password('Chrome Safe Storage', 'Chrome')
                            my_pass = my_pass.encode('utf8')
                            iterations = 1003
                            self.cached_key = PBKDF2(my_pass, salt, length, iterations)
                        decrypted_value = chrome_decrypt(encrypted_value, key=self.cached_key)
                    except:
                        pass
                else:
                    decrypted_value = "<encrypted>"

                # If running Chromium on Linux.
                # Unlike Win/Mac, we can decrypt Linux cookies without the user's pw
                if decrypted_value is "<encrypted>" and self.available_decrypts['linux'] is 1:
                    try:
                        if not self.cached_key:
                            my_pass = 'peanuts'
                            iterations = 1
                            self.cached_key = PBKDF2(my_pass, salt, length, iterations)
                        decrypted_value = chrome_decrypt(encrypted_value, key=self.cached_key)
                    except:
                        pass

        return decrypted_value 
開發者ID:obsidianforensics,項目名稱:hindsight,代碼行數:63,代碼來源:chrome.py


注:本文中的Cryptodome.Protocol.KDF.PBKDF2屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。