本文整理汇总了Python中kmip.services.kmip_client.KMIPProxy.create_key_pair方法的典型用法代码示例。如果您正苦于以下问题:Python KMIPProxy.create_key_pair方法的具体用法?Python KMIPProxy.create_key_pair怎么用?Python KMIPProxy.create_key_pair使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kmip.services.kmip_client.KMIPProxy
的用法示例。
在下文中一共展示了KMIPProxy.create_key_pair方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProxyKmipClient
# 需要导入模块: from kmip.services.kmip_client import KMIPProxy [as 别名]
# 或者: from kmip.services.kmip_client.KMIPProxy import create_key_pair [as 别名]
#.........这里部分代码省略.........
Raises:
ClientConnectionNotOpen: if the client connection is unusable
KmipOperationFailure: if the operation result is a failure
TypeError: if the input arguments are invalid
"""
# Check inputs
if not isinstance(algorithm, enums.CryptographicAlgorithm):
raise TypeError(
"algorithm must be a CryptographicAlgorithm enumeration")
elif not isinstance(length, six.integer_types) or length <= 0:
raise TypeError("length must be a positive integer")
# Verify that operations can be given at this time
if not self._is_open:
raise exceptions.ClientConnectionNotOpen()
# Create the template containing the attributes
attributes = self._build_key_attributes(algorithm, length)
template = cobjects.TemplateAttribute(attributes=attributes)
# Create the symmetric key and handle the results
result = self.proxy.create(enums.ObjectType.SYMMETRIC_KEY, template)
status = result.result_status.enum
if status == enums.ResultStatus.SUCCESS:
uid = result.uuid.value
return uid
else:
reason = result.result_reason.enum
message = result.result_message.value
raise exceptions.KmipOperationFailure(status, reason, message)
def create_key_pair(self, algorithm, length):
"""
Create an asymmetric key pair on a KMIP appliance.
Args:
algorithm (CryptographicAlgorithm): An enumeration defining the
algorithm to use to generate the key pair.
length (int): The length in bits for the key pair.
Returns:
string: The uid of the newly created public key.
string: The uid of the newly created private key.
Raises:
ClientConnectionNotOpen: if the client connection is unusable
KmipOperationFailure: if the operation result is a failure
TypeError: if the input arguments are invalid
"""
# Check inputs
if not isinstance(algorithm, enums.CryptographicAlgorithm):
raise TypeError(
"algorithm must be a CryptographicAlgorithm enumeration")
elif not isinstance(length, six.integer_types) or length <= 0:
raise TypeError("length must be a positive integer")
# Verify that operations can be given at this time
if not self._is_open:
raise exceptions.ClientConnectionNotOpen()
# Create the template containing the attributes
attributes = self._build_key_attributes(algorithm, length)
template = cobjects.CommonTemplateAttribute(attributes=attributes)
示例2: CryptographicUsageMask
# 需要导入模块: from kmip.services.kmip_client import KMIPProxy [as 别名]
# 或者: from kmip.services.kmip_client.KMIPProxy import create_key_pair [as 别名]
value = CryptographicUsageMask(
UsageMaskEnum.ENCRYPT.value | UsageMaskEnum.DECRYPT.value)
usage_mask = Attribute(attribute_name=name, attribute_value=value)
attribute_type = AttributeType.CRYPTOGRAPHIC_LENGTH
length_obj = attribute_factory.create_attribute(attribute_type,
length)
attributes = [algorithm_obj, length_obj, name, usage_mask]
common = CommonTemplateAttribute(attributes=attributes)
private = PrivateKeyTemplateAttribute(attributes=attributes)
public = PublicKeyTemplateAttribute(attributes=attributes)
# Create the SYMMETRIC_KEY object
result = client.create_key_pair(common_template_attribute=common,
private_key_template_attribute=private,
public_key_template_attribute=public)
client.close()
# Display operation results
logger.info('create_key_pair() result status: {0}'.format(
result.result_status.enum))
if result.result_status.enum == ResultStatus.SUCCESS:
logger.info('created private key UUID: {0}'.format(
result.private_key_uuid))
logger.info('created public key UUID: {0}'.format(
result.public_key_uuid))
if result.private_key_template_attribute is not None:
logger.info('private key template attribute:')