def __str__(self): return json.dumps({ "p": util.Base64WSEncode(self.params['p']), "q": util.Base64WSEncode(self.params['q']), "g": util.Base64WSEncode(self.params['g']), "y": util.Base64WSEncode(self.params['y']), "size": self.size })
def __str__(self): return json.dumps({ "modulus": util.Base64WSEncode(self.params['modulus']), "publicExponent": util.Base64WSEncode(self.params['publicExponent']), "size": self.size })
def LoadPackedKey(packed_key_data): """ Constructs and returns a new _Session instance, initialized with the key data extracted from the provided packed_key_data, which must have been produced by _Session.packed_key. """ unpacked = util.UnpackMultipleByteArrays(packed_key_data) assert len(unpacked) == 2 aes_key_bytes = unpacked[0] hmac_key_bytes = unpacked[1] hmac_key = keys.HmacKey(util.Base64WSEncode(hmac_key_bytes), len(hmac_key_bytes) * 8) session_key = keys.AesKey(util.Base64WSEncode(aes_key_bytes), hmac_key, len(aes_key_bytes) * 8, keyinfo.CBC) return _Session.__Create(session_key, None)
def json(self): """ Returns the session key data and nonce in Json format. """ aes_key_string = json.loads(str(self.__session_key)) return json.dumps({ 'key': aes_key_string, 'nonce': util.Base64WSEncode(self.__nonce) })
def Generate(size=keyinfo.HMAC_SHA1.default_size): """ Return a newly generated HMAC-SHA1 key. @param size: length of key in bits to generate @type size: integer @return: an HMAC-SHA1 key @rtype: L{HmacKey} """ key_bytes = util.RandBytes(size / 8) key_string = util.Base64WSEncode(key_bytes) return HmacKey(key_string, size)
def Sign(self, data): """ Sign given data and return corresponding signature. For message M, outputs the signature as Header|Sig(Header.M). @param data: message to be signed @type data: string @return: signature on the data encoded as a Base64 string @rtype: string """ return util.Base64WSEncode(self.primary_key.Header() + self.__InternalSign(data))
def Generate(size=keyinfo.AES.default_size): """ Return a newly generated AES key. @param size: length of key in bits to generate @type size: integer @return: an AES key @rtype: L{AesKey} """ key_bytes = util.RandBytes(size / 8) key_string = util.Base64WSEncode(key_bytes) hmac_key = HmacKey.Generate() # use default HMAC-SHA1 key size return AesKey(key_string, hmac_key, size)
def Sign(self, data): """ Sign given data and return corresponding signature. This signature contains no header or version information. For message M, outputs the signature as Sig(M). @param data: message to be signed @type data: string @return: signature on the data encoded as a Base64 string @rtype: string """ signing_key = self.primary_key if signing_key is None: raise errors.NoPrimaryKeyError() return util.Base64WSEncode(signing_key.Sign(data))
def _ParseHeader(self, header): """ Parse the header and verify version, format info. Return key if exists. @param header: the bytes of the header of Keyczar output @type header: string @return: the key identified by the hash in the header @rtype: L{keys.Key} @raise BadVersionError: if header specifies an illegal version @raise KeyNotFoundError: if key specified in header doesn't exist """ version = ord(header[0]) if version != VERSION: raise errors.BadVersionError(version) return self.GetKey(util.Base64WSEncode(header[1:]))
def AttachedSign(self, data, nonce): """ Sign given data and nonce and return a blob containing both data and signature For message M, and nonce N, outputs Header|len(M)|M|Sig(Header|M|N). @param data: message to be signed @type data: string @param nonce: nonce to be included in the signature @type nonce: string @return: signature on the data encoded as a Base64 string @rtype: string """ return util.Base64WSEncode(self.primary_key.Header() + util.PackByteArray(data) + self.__InternalSign(data, nonce))
def __str__(self): return json.dumps({ "publicKey": json.loads(str(self.public_key)), "privateExponent": util.Base64WSEncode(self.params['privateExponent']), "primeP": util.Base64WSEncode(self.params['primeP']), "primeQ": util.Base64WSEncode(self.params['primeQ']), "primeExponentP": util.Base64WSEncode(self.params['primeExponentP']), "primeExponentQ": util.Base64WSEncode(self.params['primeExponentQ']), "crtCoefficient": util.Base64WSEncode(self.params['crtCoefficient']), "size": self.size })
def _Hash(self): fullhash = util.Hash(util.IntToBytes(len(self.key_bytes)), self.key_bytes, self.hmac_key.key_bytes) return util.Base64WSEncode(fullhash[:keyczar.KEY_HASH_SIZE])
def _Hash(self): fullhash = util.PrefixHash(util.TrimBytes(self._params['p']), util.TrimBytes(self._params['q']), util.TrimBytes(self._params['g']), util.TrimBytes(self._params['y'])) return util.Base64WSEncode(fullhash[:keyczar.KEY_HASH_SIZE])
def __str__(self): return json.dumps({ "publicKey": json.loads(str(self.public_key)), "x": util.Base64WSEncode(self.params['x']), "size": self.size })
def WrapperFunction(*args): output = method(*args) b64_output = util.Base64WSEncode(output) return json.dumps({"output": b64_output})
def _Hash(self): fullhash = util.Hash(self.key_bytes) return util.Base64WSEncode(fullhash[:keyczar.KEY_HASH_SIZE])
def _Hash(self): """Compute and return the hash_id id of this key. Can override default hash_id.""" fullhash = util.Hash(util.IntToBytes(len(self.key_bytes)), self.key_bytes) return util.Base64WSEncode(fullhash[:keyczar.KEY_HASH_SIZE])
def _Hash(self): fullhash = util.PrefixHash( util.TrimBytes(self._params['modulus']), util.TrimBytes(self._params['publicExponent'])) return util.Base64WSEncode(fullhash[:keyczar.KEY_HASH_SIZE])