예제 #1
0
 def public(self, data):
   """Public Key Transform: encrypt, verify
   
   Args:
     data: str of bytestring to transform
   Returns:
     str: of bytestring of transformed `data`
   Raises:
     ValueError: Data too long for key size.
   """
   message = integers.bytes_to_int(data)
   
   if self.modulus <= message:
     raise ValueError, "data too long for key size"
   
   cypher = pow(message, self.exponent, self.modulus)
   return integers.int_to_bytes(cypher)
예제 #2
0
 def private(self, data):
   """Private Key Transform: decrypt, sign
   
   Args:
     data: str of bytestring to transform
   Returns:
     str: of bytestring of transformed `data`
   Raises:
     ValueError: Data too long for key size.
     AttributeError: No private component in encryption key.
   """
   cypher = integers.bytes_to_int(data)
   
   if self.modulus <= cypher:
     raise ValueError, "Data too long for key size."
   elif not self.decrypt:
     raise AttributeError, "No private component in encryption key."
   
   message = pow(cypher, self.decrypt, self.modulus)
   return integers.int_to_bytes(message)
예제 #3
0
 def make_value_from_datastore(self, value):
   if value is None:
     return None
   return integers.bytes_to_int(value)