本文整理匯總了Python中base64.b16decode方法的典型用法代碼示例。如果您正苦於以下問題:Python base64.b16decode方法的具體用法?Python base64.b16decode怎麽用?Python base64.b16decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類base64
的用法示例。
在下文中一共展示了base64.b16decode方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _filter_decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def _filter_decode(self, data, encoding):
if its.py_v3 and isinstance(data, bytes):
data = data.decode('utf-8')
encoding = encoding.lower()
encoding = re.sub(r'^(base|rot)-(\d\d)$', r'\1\2', encoding)
if encoding == 'base16' or encoding == 'hex':
data = base64.b16decode(data)
elif encoding == 'base32':
data = base64.b32decode(data)
elif encoding == 'base64':
data = base64.b64decode(data)
elif encoding == 'rot13':
data = codecs.getdecoder('rot-13')(data)[0]
else:
raise ValueError('Unknown encoding type: ' + encoding)
if its.py_v3 and isinstance(data, bytes):
data = data.decode('utf-8')
return data
示例2: __init__
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def __init__(self, onion_router):
""":type onion_router: OnionRouter"""
self._onion_router = onion_router
# To perform the handshake, the client needs to know an identity key
# digest for the server, and an NTOR onion key (a curve25519 public
# key) for that server. Call the NTOR onion key "B". The client
# generates a temporary key-pair:
# x,X = KEYGEN()
self._ed25519 = Ed25519()
self._x = self._ed25519.create_secret_key()
self._X = self._ed25519.get_public_key(self._x)
self._B = b64decode(self._onion_router.key_ntor.encode())
# and generates a client-side handshake with contents:
# NODE_ID Server identity digest [ID_LENGTH bytes]
# KEYID KEYID(B) [H_LENGTH bytes]
# CLIENT_PK X [G_LENGTH bytes]
self._handshake = b16decode(self._onion_router.identity.encode())
self._handshake += self._B
self._handshake += self._X
示例3: test_b16decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def test_b16decode(self):
eq = self.assertEqual
eq(base64.b16decode(b'0102ABCDEF'), b'\x01\x02\xab\xcd\xef')
eq(base64.b16decode('0102ABCDEF'), b'\x01\x02\xab\xcd\xef')
eq(base64.b16decode(b'00'), b'\x00')
eq(base64.b16decode('00'), b'\x00')
# Lower case is not allowed without a flag
self.assertRaises(binascii.Error, base64.b16decode, b'0102abcdef')
self.assertRaises(binascii.Error, base64.b16decode, '0102abcdef')
# Case fold
eq(base64.b16decode(b'0102abcdef', True), b'\x01\x02\xab\xcd\xef')
eq(base64.b16decode('0102abcdef', True), b'\x01\x02\xab\xcd\xef')
# Non-bytes
self.check_other_types(base64.b16decode, b"0102ABCDEF",
b'\x01\x02\xab\xcd\xef')
self.check_decode_type_errors(base64.b16decode)
eq(base64.b16decode(bytearray(b"0102abcdef"), True),
b'\x01\x02\xab\xcd\xef')
eq(base64.b16decode(memoryview(b"0102abcdef"), True),
b'\x01\x02\xab\xcd\xef')
eq(base64.b16decode(array('B', b"0102abcdef"), True),
b'\x01\x02\xab\xcd\xef')
示例4: Decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def Decode(self, encoded_data):
"""Decode the encoded data.
Args:
encoded_data (byte): encoded data.
Returns:
tuple(bytes, bytes): decoded data and remaining encoded data.
Raises:
BackEndError: if the base16 stream cannot be decoded.
"""
try:
decoded_data = base64.b16decode(encoded_data, casefold=False)
except (TypeError, binascii.Error) as exception:
raise errors.BackEndError(
'Unable to decode base16 stream with error: {0!s}.'.format(
exception))
return decoded_data, b''
示例5: b16_slug_to_arguments
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def b16_slug_to_arguments(b16_slug):
"""
Raises B16DecodingFail exception on
"""
try:
url = b16decode(b16_slug.decode('utf-8'))
except BinaryError:
raise B16DecodingFail
except TypeError:
raise B16DecodingFail('Non-base16 digit found')
except AttributeError:
raise B16DecodingFail("b16_slug must have a 'decode' method.")
try:
app, model, pk = url.decode('utf-8').split('/')[0:3]
except UnicodeDecodeError:
raise B16DecodingFail("Invalid b16_slug passed")
return app, model, pk
示例6: decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def decode(self, text):
try:
return base64.b16decode(text.upper())
except:
return ""
示例7: encrypt
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def encrypt():
cipher = AES.new(base64.b16decode(key, casefold=True), AES.MODE_ECB)
return base64.b16encode(cipher.encrypt(flag))
# flush output immediately
示例8: fromhex
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def fromhex(s):
return base64.b16decode(s.replace(' ', ''))
示例9: test_b16decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def test_b16decode(self):
eq = self.assertEqual
eq(base64.b16decode('0102ABCDEF'), '\x01\x02\xab\xcd\xef')
eq(base64.b16decode('00'), '\x00')
# Lower case is not allowed without a flag
self.assertRaises(TypeError, base64.b16decode, '0102abcdef')
# Case fold
eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
# Non-bytes
eq(base64.b16decode(bytearray("0102ABCDEF")), '\x01\x02\xab\xcd\xef')
# Non-alphabet characters
self.assertRaises(TypeError, base64.b16decode, '0102AG')
# Incorrect "padding"
self.assertRaises(TypeError, base64.b16decode, '010')
示例10: _base16_decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def _base16_decode(self, decode_string):
decoder = base64.b16decode(decode_string, casefol=False)
return decoder
示例11: b64from16
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def b64from16(val):
""" ASCII encoded base 64 string from a base 16 digest """
return b64from256(b16decode(val, casefold=True))
示例12: test_b16decode
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def test_b16decode(self):
eq = self.assertEqual
eq(base64.b16decode('0102ABCDEF'), '\x01\x02\xab\xcd\xef')
eq(base64.b16decode('00'), '\x00')
# Lower case is not allowed without a flag
self.assertRaises(TypeError, base64.b16decode, '0102abcdef')
# Case fold
eq(base64.b16decode('0102abcdef', True), '\x01\x02\xab\xcd\xef')
# Non-bytes
eq(base64.b16decode(bytearray("0102ABCDEF")), '\x01\x02\xab\xcd\xef')
示例13: macpack
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def macpack(mac):
return base64.b16decode(mac.replace(':', '').replace('-', '').encode('ascii'))
示例14: _to_b32
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def _to_b32(length, value):
'''
Convert value to base 32, given that it's supposed to have the same
length as the digest we're about to compare it to
'''
if len(value) == length:
return value # casefold needed here? -- rfc recommends not allowing
if len(value) > length:
binary = base64.b16decode(value, casefold=True)
else:
binary = _b64_wrapper(value)
return to_native_str(base64.b32encode(binary), encoding='ascii')
示例15: main
# 需要導入模塊: import base64 [as 別名]
# 或者: from base64 import b16decode [as 別名]
def main():
inp = input("->")
encoded = inp.encode("utf-8") # encoded the input (we need a bytes like object)
b16encoded = base64.b16encode(encoded) # b16encoded the encoded string
print(b16encoded)
print(base64.b16decode(b16encoded).decode("utf-8")) # decoded it