Example #1
0
    def test_rsa_decryption(self):
        dataSet = self.rsaKeyTestData

        pkcs8 = base64.b64decode(dataSet.privateKeyPkcs8Unencrypted)
        key = TpmPrivateKey()
        key.loadPkcs8(pkcs8)

        plainText = Blob([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07])

        cipherTextBase64 = (
            "i2XNpZ2JbLa4JmBTdDrGmsd4/0C+p+BSCpW3MuPBNe5uChQ0eRO1dvjTnEqwSECY\n"
            +
            "38en9JZwcyb0It/TSFNXHlq+Z1ZpffnjIJxQR9HcgwvwQJh6WRH0vu38tvGkGuNv\n"
            +
            "60Rdn85hqSy1CikmXCeWXL9yCqeqcP21R94G/T3FuA+c1FtFko8KOzCwvrTXMO6n\n"
            +
            "5PNsqlLXabSGr+jz4EwOsSCgPkiDf9U6tXoSPRA2/YvqFQdaiUXIVlomESvaqqZ8\n"
            +
            "FxPs2BON0lobM8gT+xdzbRKofp+rNjNK+5uWyeOnXJwzCszh17cdJl2BH1dZwaVD\n"
            + "PmTiSdeDQXZ94U5boDQ4Aw==\n")

        cipherText = base64.b64decode(cipherTextBase64)

        decryptedText = key.decrypt(cipherText)

        self.assertTrue(decryptedText.equals(plainText))
Example #2
0
    def decrypt(keyBits, encryptedData, params):
        """
        Decrypt the encryptedData using the keyBits according the encrypt params.

        :param Blob keyBits: The key value (PKCS8-encoded private key).
        :param Blob encryptedData: The data to decrypt.
        :param EncryptParams params: This decrypts according to
          params.getAlgorithmType().
        :return: The decrypted data.
        :rtype: Blob
        """
        privateKey = TpmPrivateKey()
        privateKey.loadPkcs8(keyBits.toBytes())
        return privateKey.decrypt(
          encryptedData.toBytes(), params.getAlgorithmType())
Example #3
0
    def decrypt(keyBits, encryptedData, params):
        """
        Decrypt the encryptedData using the keyBits according the encrypt params.

        :param Blob keyBits: The key value (PKCS8-encoded private key).
        :param Blob encryptedData: The data to decrypt.
        :param EncryptParams params: This decrypts according to
          params.getAlgorithmType().
        :return: The decrypted data.
        :rtype: Blob
        """
        privateKey = TpmPrivateKey()
        privateKey.loadPkcs8(keyBits.toBytes())
        return privateKey.decrypt(encryptedData.toBytes(),
                                  params.getAlgorithmType())
    def test_rsa_decryption(self):
        dataSet = self.rsaKeyTestData

        pkcs8 = base64.b64decode(dataSet.privateKeyPkcs8Unencrypted)
        key =  TpmPrivateKey()
        key.loadPkcs8(pkcs8)

        plainText = Blob([0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07])

        cipherTextBase64 = (
          "i2XNpZ2JbLa4JmBTdDrGmsd4/0C+p+BSCpW3MuPBNe5uChQ0eRO1dvjTnEqwSECY\n" +
          "38en9JZwcyb0It/TSFNXHlq+Z1ZpffnjIJxQR9HcgwvwQJh6WRH0vu38tvGkGuNv\n" +
          "60Rdn85hqSy1CikmXCeWXL9yCqeqcP21R94G/T3FuA+c1FtFko8KOzCwvrTXMO6n\n" +
          "5PNsqlLXabSGr+jz4EwOsSCgPkiDf9U6tXoSPRA2/YvqFQdaiUXIVlomESvaqqZ8\n" +
          "FxPs2BON0lobM8gT+xdzbRKofp+rNjNK+5uWyeOnXJwzCszh17cdJl2BH1dZwaVD\n" +
          "PmTiSdeDQXZ94U5boDQ4Aw==\n")

        cipherText = base64.b64decode(cipherTextBase64)

        decryptedText = key.decrypt(cipherText)

        self.assertTrue(decryptedText.equals(plainText))