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


Python Password.encrypt方法代碼示例

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


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

示例1: testBoth

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
 def testBoth(self):
     f, filename = tempfile.mkstemp()
     self.addCleanup(os.unlink, filename)
     Password.KEYFILE = filename
     pwd = "Test password"
     encrypted = Password.encrypt(pwd)
     self.assertEqual(pwd, Password.decrypt(encrypted))
     self.assertEqual(os)
開發者ID:cakofony,項目名稱:virt-who,代碼行數:10,代碼來源:test_password.py

示例2: testBoth

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
 def testBoth(self):
     f, filename = tempfile.mkstemp()
     self.addCleanup(os.unlink, filename)
     Password.KEYFILE = filename
     pwd = "Test password"
     Password._can_write = MagicMock(retun_value=True)
     encrypted = Password.encrypt(pwd)
     self.assertEqual(pwd, Password.decrypt(encrypted))
開發者ID:bluesky-sgao,項目名稱:virt-who,代碼行數:10,代碼來源:test_password.py

示例3: testCryptedPassword

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
    def testCryptedPassword(self, password):
        from password import Password
        password.return_value = (hexlify(Password._generate_key()), hexlify(Password._generate_key()))
        passwd = "TestSecretPassword!"
        crypted = hexlify(Password.encrypt(passwd))

        filename = os.path.join(self.config_dir, "test.conf")
        with open(filename, "w") as f:
            f.write("""
[test]
type=esx
server=1.2.3.4
username=admin
encrypted_password=%s
owner=root
env=staging
""" % crypted)
        manager = ConfigManager(self.logger, self.config_dir)
        self.assertEqual(len(manager.configs), 1)
        self.assertEqual(manager.configs[0].password, passwd)
開發者ID:wido-gg,項目名稱:virt-who,代碼行數:22,代碼來源:test_config.py

示例4: getpass

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
        print """Utility that encrypts passwords for virt-who.

Enter password that should be encrypted. This encrypted password then can be
supplied to virt-who configuration.

This command must be executed as root!

WARNING: root user can still decrypt encrypted passwords!
"""
        sys.exit(0)

    if os.getuid() != 0:
        print >> sys.stderr, "Only root can encrypt passwords"
        sys.exit(1)

    try:
        pwd = getpass("Password: ")
    except (KeyboardInterrupt, EOFError):
        print
        sys.exit(1)
    try:
        enc = Password.encrypt(pwd)
    except UnwritableKeyFile:
        print >> sys.stderr, "Keyfile %s doesn't exist and can't be created, rerun as root" % Password.KEYFILE
        sys.exit(1)
    except InvalidKeyFile:
        print >> sys.stderr, "Can't access keyfile %s, rerun as root" % Password.KEYFILE
        sys.exit(1)
    print >> sys.stderr, "Use following as value for encrypted_password key in the configuration file:"
    print hexlify(enc)
開發者ID:wido-gg,項目名稱:virt-who,代碼行數:32,代碼來源:virtwhopassword.py

示例5: testBackslash

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
 def testBackslash(self):
     self.mock_pwd_file()
     pwd = 'abc\\def'
     self.assertEqual(
         Password.decrypt(Password.encrypt(pwd)),
         pwd)
開發者ID:wido-gg,項目名稱:virt-who,代碼行數:8,代碼來源:test_password.py

示例6: testPercent

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
 def testPercent(self):
     self.mock_pwd_file()
     pwd = 'abc%%def'
     self.assertEqual(
         Password.decrypt(Password.encrypt(pwd)),
         pwd)
開發者ID:wido-gg,項目名稱:virt-who,代碼行數:8,代碼來源:test_password.py

示例7: testBoth

# 需要導入模塊: from password import Password [as 別名]
# 或者: from password.Password import encrypt [as 別名]
 def testBoth(self):
     self.mock_pwd_file()
     pwd = "Test password"
     encrypted = Password.encrypt(pwd)
     self.assertEqual(pwd, Password.decrypt(encrypted))
開發者ID:wido-gg,項目名稱:virt-who,代碼行數:7,代碼來源:test_password.py


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