Beispiel #1
0
    def test_rsa_pkcs1(self, key_template, hash_algo, modulus_size, exponent):
        self.assertEqual(
            key_template.type_url,
            'type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey')
        self.assertEqual(key_template.output_prefix_type, tink_pb2.TINK)

        key_format = rsa_ssa_pkcs1_pb2.RsaSsaPkcs1KeyFormat()
        key_format.ParseFromString(key_template.value)
        self.assertEqual(key_format.modulus_size_in_bits, modulus_size)
        self.assertEqual(key_format.params.hash_type, hash_algo)
        self.assertEqual(bytes_to_num(key_format.public_exponent), exponent)
Beispiel #2
0
def _create_rsa_ssa_pkcs1_key_template(
        hash_type: common_pb2.HashType, modulus_size: int,
        public_exponent: int) -> tink_pb2.KeyTemplate:
    """Creates a KeyTemplate containing an RsaSsaPkcs1KeyFormat."""
    params = rsa_ssa_pkcs1_pb2.RsaSsaPkcs1Params(hash_type=hash_type)
    key_format = rsa_ssa_pkcs1_pb2.RsaSsaPkcs1KeyFormat(
        params=params,
        modulus_size_in_bits=modulus_size,
        public_exponent=big_integer_util.num_to_bytes(public_exponent))
    key_template = tink_pb2.KeyTemplate(value=key_format.SerializeToString(),
                                        type_url=_RSA_PKCS1_KEY_TYPE_URL,
                                        output_prefix_type=tink_pb2.TINK)

    return key_template
Beispiel #3
0
    def test_rsa_pkcs1(self, key_template, hash_algo, modulus_size, exponent):
        self.assertEqual(
            key_template.type_url,
            'type.googleapis.com/google.crypto.tink.RsaSsaPkcs1PrivateKey')
        self.assertEqual(key_template.output_prefix_type, tink_pb2.TINK)

        key_format = rsa_ssa_pkcs1_pb2.RsaSsaPkcs1KeyFormat()
        key_format.ParseFromString(key_template.value)
        self.assertEqual(key_format.modulus_size_in_bits, modulus_size)
        self.assertEqual(key_format.params.hash_type, hash_algo)
        self.assertEqual(bytes_to_num(key_format.public_exponent), exponent)

        # Check that the template works with the key manager
        key_manager = core.Registry.key_manager(key_template.type_url)
        key_manager.new_key_data(key_template)