本文整理匯總了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)
示例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))
示例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)
示例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)
示例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)
示例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)
示例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))