本文整理汇总了Python中simplecrypt.decrypt函数的典型用法代码示例。如果您正苦于以下问题:Python decrypt函数的具体用法?Python decrypt怎么用?Python decrypt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了decrypt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_bytes_password
def test_bytes_password(self):
ptext = decrypt(b'password', encrypt(b'password', b'message'))
assert ptext == b'message', ptext
ptext = decrypt('password', encrypt(b'password', b'message'))
assert ptext == b'message', ptext
ptext = decrypt(b'password', encrypt('password', b'message'))
assert ptext == b'message', ptext
示例2: test_unicode_ciphertext
def test_unicode_ciphertext(self):
u_ciphertext = b'some string'.decode('utf8')
try:
decrypt('password', u_ciphertext)
assert False, 'expected error'
except DecryptionException as e:
assert 'bytes' in str(e), e
示例3: test_bad_password
def test_bad_password(self):
ctext = bytearray(encrypt('password', 'message'))
try:
decrypt('badpassword', ctext)
assert False, 'expected error'
except DecryptionException as e:
assert 'Bad password' in str(e), e
示例4: get_profile
def get_profile(self, profile, pwd):
self.c.execute("SELECT * FROM profiles WHERE profile=?", (profile,))
res = self.c.fetchone()
uname = simplecrypt.decrypt(pwd, res[1]).decode('utf-8')
api_key = simplecrypt.decrypt(pwd, res[2]).decode('utf-8')
token = simplecrypt.decrypt(pwd, res[3]).decode('utf-8')
return (uname, pwd, api_key, token)
示例5: test_modification
def test_modification(self):
ctext = bytearray(encrypt('password', 'message'))
ctext[10] = ctext[10] ^ 85
try:
decrypt('password', ctext)
assert False, 'expected error'
except DecryptionException as e:
assert 'modified' in str(e), e
示例6: test_length
def test_length(self):
ctext = encrypt('password', '')
assert not decrypt('password', ctext)
try:
decrypt('password', bytes(bytearray(ctext)[:-1]))
assert False, 'expected error'
except DecryptionException as e:
assert 'Missing' in str(e), e
示例7: test_unicode_plaintext
def test_unicode_plaintext(self):
ptext = decrypt(u'password', encrypt(u'password', u'message'))
assert ptext.decode('utf8') == 'message', ptext
ptext = decrypt(u'password', encrypt(u'password', u'message'.encode('utf8')))
assert ptext == 'message'.encode('utf8'), ptext
ptext = decrypt(u'password', encrypt(u'password', u'¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹'))
assert ptext.decode('utf8') == u'¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹', ptext
ptext = decrypt(u'password', encrypt(u'password', u'¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹'.encode('utf8')))
assert ptext == u'¥£€$¢₡₢₣₤₥₦₧₨₩₪₫₭₮₯₹'.encode('utf8'), ptext
示例8: load_db
def load_db(password=''):
creds = {}
keychain = Keychain()
account = getlogin()
payload = keychain.get_generic_password(KEYCHAIN, account, SERVICE_NAME)
if payload and 'password' in payload:
parts = payload['password'].split(JOIN_STRING)
if(len(parts) > 1):
creds['password'] = password and decrypt(password, unhexlify(parts[1])) or parts[1]
creds['username'] = password and decrypt(password, unhexlify(parts[0])) or parts[0]
return creds
示例9: get_config
def get_config():
secret = os.getenv('SECRET_KEY', 'my_secret_key')
current_path = os.path.dirname(os.path.realpath(__file__))
config = ConfigParser()
config.read(os.path.join(current_path, 'taskstore.ini'))
host = base64.b64decode(config.get('db_connection', 'host'))
user = base64.b64decode(config.get('db_connection', 'user'))
password = base64.b64decode(config.get('db_connection', 'password'))
db = base64.b64decode(config.get('db_connection', 'db'))
return (decrypt(secret, host),
decrypt(secret, user),
decrypt(secret, password),
decrypt(secret, db))
示例10: get_config
def get_config():
secret = os.getenv('SECRET_KEY', 'my_secret_key')
current_path = os.path.dirname(os.path.realpath(__file__))
config = ConfigParser()
config.read(os.path.join(current_path, 'mail.ini'))
host = base64.b64decode(config.get('smtp', 'host'))
user = base64.b64decode(config.get('smtp', 'user'))
password = base64.b64decode(config.get('smtp', 'password'))
admin = base64.b64decode(config.get('smtp', 'admin'))
return (decrypt(secret, host),
decrypt(secret, user),
decrypt(secret, password),
decrypt(secret, admin))
示例11: decrypt_disclaimers
def decrypt_disclaimers(input, output, fieldsep, rowsep):
if PASSWORD is None:
print('You need to set the SIMPLECRYPT_PASSWORD')
return
if output is None:
# timestamp the filename with the datetime it was downloaded
timestamp = time.strftime(
'%Y%m%d%H%M', time.gmtime(os.path.getctime(input.name))
)
output = 'disclaimers_backup_{}.csv'.format(timestamp)
encrypted_text = input.read()
decrypted_text = decrypt(PASSWORD, encrypted_text)
decrypted_text = str(decrypted_text).lstrip("b'").rstrip("'")
decrypted_data = decrypted_text.split(fieldsep)
with open(output, 'wt') as out:
wr = csv.writer(out)
for entry in decrypted_data:
data = entry.split(rowsep)
wr.writerow([smart_str(datum) for datum in data])
os.unlink(input.name)
print(
'{} records decrypted and written to {}'.format(
len(decrypted_data) - 1, output
)
)
示例12: item
def item(id):
myitem = PasswordRecords.query.get_or_404(id)
site = myitem.displayname
username = myitem.username
password = decrypt(globalkey, myitem.password)
detail = myitem.detail
return render_template('item.html',name=site,name2="http://" + site,username=username,password=password,detail=detail)
示例13: read_config
def read_config(file_path):
"""
Tries to read config from 2 types of files.
If json file is available it will use that one.
If there is no json file it will use the encrypted file.
"""
if file_path.endswith(".json"):
if os.path.isfile(file_path):
print(green("Load config %s" % (file_path)))
with open(file_path) as json_config:
try:
return json.load(json_config)
except Exception, e:
abort(red("Cannot read config, is the config correct?. `%s`" % e))
encrypt_file_path = "%s.encrypt" % file_path
if not os.path.isfile(encrypt_file_path):
abort(red("No config `%s` found." % encrypt_file_path))
with open(encrypt_file_path) as ciphertext:
password = utils.get_master_password()
try:
config = decrypt(env.master_password, ciphertext.read()).decode('UTF-8')
except DecryptionException, e:
abort(red(e))
try:
return json.loads(config)
except Exception, e:
abort(red("Cannot read config, is the config correct? `%s`" % e))
示例14: do_revoke
def do_revoke(self):
try:
authid = self.request.get('authid')
if authid is None or authid == '':
return "Error: No authid in query"
if authid.find(':') <= 0:
return 'Error: Invalid authid in query'
keyid = authid[:authid.index(':')]
password = authid[authid.index(':') + 1:]
if keyid == 'v2':
return 'Error: The token must be revoked from the service provider. You can de-authorize the application on the storage providers website.'
entry = dbmodel.AuthToken.get_by_key_name(keyid)
if entry is None:
return 'Error: No such user'
data = base64.b64decode(entry.blob)
resp = None
try:
resp = json.loads(simplecrypt.decrypt(password, data).decode('utf8'))
except:
logging.exception('decrypt error')
return 'Error: Invalid authid password'
entry.delete()
return "Token revoked"
except:
logging.exception('handler error')
return 'Error: Server error'
示例15: _create_client
def _create_client(self, data):
""" Creates client from data
implements some password obfuscation
:param dict data: dictionary with client params
:return: Client instance
:rtype: openerp_proxy.client
"""
if 'pwd' not in data:
data = data.copy()
if self.session.option('store_passwords') and 'password' in data:
import base64
encoded_pwd = data.pop('password').encode('utf8')
crypter, password = base64.b64decode(encoded_pwd).split(b':')
if crypter == b'simplecrypt': # pragma: no cover
# Legacy support
import simplecrypt
data['pwd'] = simplecrypt.decrypt(
Client.to_url(data), base64.b64decode(password))
elif crypter == b'plain':
# Current crypter
data['pwd'] = password.decode('utf-8')
else: # pragma: no cover
raise Exception("Unknown crypter (%s) used in session"
"" % repr(crypter))
else:
# TODO: check if in interactive mode
data['pwd'] = getpass('Password: ') # pragma: no cover
return super(SessionClientManager, self)._create_client(data)