Esempio n. 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)
Esempio n. 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)
Esempio n. 3
0
 def size(self):
   return len(integers.int_to_bytes(self.modulus))
Esempio n. 4
0
 def get_value_for_datastore(self, model_instance):
   s = super(LongProperty, self).get_value_for_datastore(model_instance)
   return integers.int_to_bytes(s)