python bin a_Python binascii.a2b_base64方法代碼示例

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

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

示例1: b64decode

​點讚 7

# 需要導入模塊: import binascii [as 別名]

# 或者: from binascii import a2b_base64 [as 別名]

def b64decode(s, altchars=None, validate=False):

"""Decode a Base64 encoded byte string.

s is the byte string to decode. Optional altchars must be a

string of length 2 which specifies the alternative alphabet used

instead of the '+' and '/' characters.

The decoded string is returned. A binascii.Error is raised if s is

incorrectly padded.

If validate is False (the default), non-base64-alphabet characters are

discarded prior to the padding check. If validate is True,

non-base64-alphabet characters in the input result in a binascii.Error.

"""

s = _bytes_from_decode_data(s)

if altchars is not None:

altchars = _bytes_from_decode_data(altchars)

assert len(altchars) == 2, repr(altchars)

s = s.translate(bytes.maketrans(altchars, b'+/'))

if validate and not re.match(b'^[A-Za-z0-9+/]*={0,2}$', s):

raise binascii.Error('Non-base64 digit found')

return binascii.a2b_base64(s)

開發者ID:war-and-code,項目名稱:jawfish,代碼行數:24,

示例2: CheckBasicAuth

​點讚 6

# 需要導入模塊: import binascii [as 別名]

# 或者: from binascii import a2b_base64 [as 別名]

def CheckBasicAuth(self, username, password) :

if not isinstance(username, str) :

raise ValueError('"username" must be a string.')

if not isinstance(password, str) :

raise ValueError('"password" must be a string.')

auth = self.Authorization

if auth :

try :

auth = auth.split()

if len(auth) == 2 and auth[0].lower() == 'basic' :

auth = a2b_base64(auth[1].encode()).decode()

auth = auth.split(':')

return ( auth[0].lower() == username.lower() and \

auth[1] == password )

except :

pass

return False

# ------------------------------------------------------------------------

開發者ID:jczic,項目名稱:MicroWebSrv2,代碼行數:21,

示例3: decode

​點讚 6

# 需要導入模塊: import binascii [as 別名]

# 或者: from binascii import a2b_base64 [as 別名]

def decode(string):

"""Decode a raw base64 string, returning a bytes object.

This function does not parse a full MIME header value encoded with

base64 (like =?iso-8895-1?b?bmloISBuaWgh?=) -- please use the high

level email.header class for that functionality.

"""

if not string:

return bytes()

elif isinstance(string, str):

return a2b_base64(string.encode('raw-unicode-escape'))

else:

return a2b_base64(string)

# For convenience and backwards compatibility w/ standard base64 module

開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:18,

示例4: create

​點讚 6

# 需要導入模塊: import binascii [as 別名]

# 或者: from binascii import a2b_base64 [as 別名]

def create(vek, keySizeBytes, certificatePath):

#print("VEK: " + str(binascii.hexlify(vek)))

publicKeyPem = open(certificatePath).read()

publicKey = RSA.importKey(publicKeyPem)

# Convert from PEM to DER

lines = publicKeyPem.replace(" ", '').split()

publicKeyDer = binascii.a2b_base64(''.join(lines[1:-1]))<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值