当前位置: 首页>>代码示例>>Python>>正文


Python Basic.bytes_to_long方法代码示例

本文整理汇总了Python中common.utils.Basic.bytes_to_long方法的典型用法代码示例。如果您正苦于以下问题:Python Basic.bytes_to_long方法的具体用法?Python Basic.bytes_to_long怎么用?Python Basic.bytes_to_long使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在common.utils.Basic的用法示例。


在下文中一共展示了Basic.bytes_to_long方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load_public_key

# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import bytes_to_long [as 别名]
  def load_public_key(s=None, fileName=None):
    assert s or fileName, "load_public_key must be passed either a string or file"
    if fileName:
      key = M2Crypto.RSA.load_pub_key(fileName)
      publicKey = PublicKey(key)
      eStr, nStr = key.pub()
      publicKey.e = Basic.bytes_to_long(eStr[4:])
      publicKey.n = Basic.bytes_to_long(nStr[4:])
      return publicKey
    else:
      start = s.find("-----BEGIN RSA PUBLIC KEY-----")
      end = s.find("-----END RSA PUBLIC KEY-----")
      if start == -1:
        raise Exception("Missing PEM prefix")
      if end == -1:
        raise Exception("Missing PEM postfix")
      remainder = s[end+len("-----END RSA PUBLIC KEY-----\n\r"):]
      s = s[start+len("-----BEGIN RSA PUBLIC KEY-----") : end]

      parser = decoder.decode(s.decode("base64"))[0]
      n = long(parser.getComponentByPosition(0))
      e = long(parser.getComponentByPosition(1))
      
      publicKey = PublicKey(n, e)
      return publicKey, remainder
开发者ID:clawplach,项目名称:BitBlinder,代码行数:27,代码来源:PublicKey.py

示例2: __init__

# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import bytes_to_long [as 别名]
 def __init__(self, constructor):
   """Pass either file location of public key or bit length for new key."""
   if isinstance(constructor, basestring):
     #load the key found at location: constructor
     self.key = M2Crypto.RSA.load_key(constructor)
   elif type(constructor) == int:
     #generate a key of length constructor
     def silence(*args):
       pass
     self.key = M2Crypto.RSA.gen_key(constructor, 65537, silence)
   else:
     raise TypeError('invalid argument: %s'%constructor)
   eStr, nStr = self.key.pub()
   self.e = Basic.bytes_to_long(eStr[4:])
   self.n = Basic.bytes_to_long(nStr[4:])
   #: length of the key in bytes (used in blinding/unblinding)
   self.keyLen = len(self.key)
开发者ID:clawplach,项目名称:BitBlinder,代码行数:19,代码来源:PrivateKey.py

示例3: __hash__

# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import bytes_to_long [as 别名]
 def __hash__(self):
   """Basically XOR everything together"""
   result = 0L
   for attr in self.COMPARISON_ORDER:
     val = Basic.bytes_to_long(str(getattr(self, attr)))
     result = result.__xor__(val)
   #TODO:  this is probably not exactly the right way to convert to an integer...
   INT_MAX = sys.maxint
   result = (result % (2*INT_MAX)) - INT_MAX
   return result
   
开发者ID:clawplach,项目名称:BitBlinder,代码行数:12,代码来源:EasyComparableMixin.py

示例4: unpack

# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import bytes_to_long [as 别名]
 def unpack(self, blob):
   """expects to get a struct of the form
   20s hexId
   50s username
   50s password
   128s publickey
   """
   msg = struct.unpack('!128s50s50s128s', blob)
   hexIdSig = msg[0]
   #strip out the null padding characters
   username = msg[1].replace('\x00', '')
   password = msg[2].replace('\x00', '')
   n = long(Basic.bytes_to_long(msg[3]))
   log_msg('attempting to login user: %s @ time: %s!' % (username, time.ctime()), 2)
   return (hexIdSig, username, password, n)
开发者ID:clawplach,项目名称:BitBlinder,代码行数:17,代码来源:LoginSSLserver.py

示例5: blind

# 需要导入模块: from common.utils import Basic [as 别名]
# 或者: from common.utils.Basic import bytes_to_long [as 别名]
 def blind(self, message, r, length=None):
   """Blind a message using random number r (assuming length of the key by default)
   @param message: string to be blinded
   @type message: string
   @param r: blinding factor
   @type r: long
   @param length: length of the message after blinding (needed to convert from a long to a string).
   @type long: None or int
   @return: string of message blinded with r assuming length of n
   """
   Basic.validate_type(message, types.StringType)
   Basic.validate_type(r, types.LongType)
   message = Basic.bytes_to_long(message)
   tmp = pow(r, self.e, self.n)
   tmp = (message * tmp) % self.n
   return Basic.long_to_bytes(tmp, length or self.keyLen)
开发者ID:clawplach,项目名称:BitBlinder,代码行数:18,代码来源:PublicKey.py


注:本文中的common.utils.Basic.bytes_to_long方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。