示例#1
0
    def deriveEncryptKey(keyBits):
        """
        Derive a new encrypt key from the given decrypt key value.

        :param Blob keyBits: The key value of the decrypt key.
        :return: The new encrypt key.
        :rtype: EncryptKey
        """
        return EncryptKey(keyBits)
示例#2
0
    def deriveEncryptKey(keyBits):
        """
        Derive a new encrypt key from the given decrypt key value.

        :param Blob keyBits: The key value of the decrypt key (PKCS8-encoded
          private key).
        :return: The new encrypt key (DER-encoded public key).
        :rtype: EncryptKey
        """
        privateKey = TpmPrivateKey()
        privateKey.loadPkcs8(keyBits.toBytes())
        return EncryptKey(privateKey.derivePublicKey())
示例#3
0
    def deriveEncryptKey(keyBits):
        """
        Derive a new encrypt key from the given decrypt key value.

        :param Blob keyBits: The key value of the decrypt key (PKCS8-encoded
          private key).
        :return: The new encrypt key (DER-encoded public key).
        :rtype: EncryptKey
        """
        # Decode the PKCS #8 private key.
        parsedNode = DerNode.parse(keyBits.buf(), 0)
        pkcs8Children = parsedNode.getChildren()
        algorithmIdChildren = DerNode.getSequence(pkcs8Children, 1).getChildren()
        oidString = algorithmIdChildren[0].toVal()

        if oidString != RsaAlgorithm.RSA_ENCRYPTION_OID:
          raise RuntimeError("The PKCS #8 private key is not RSA_ENCRYPTION")

        privateKey = serialization.load_der_private_key(
          keyBits.toBytes(), password = None, backend = default_backend())
        publicKeyDer = privateKey.public_key().public_bytes(
          encoding = serialization.Encoding.DER,
          format = serialization.PublicFormat.SubjectPublicKeyInfo)
        return EncryptKey(Blob(publicKeyDer, False))