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