Not Able to Use EncryptData powershell RRS feed

  • Question

  • The Encryptdata.ps1 file is giving the following error and no clue why.

    Exception calling "DecryptData" with "1" argument(s): "Bad Key.
    At E:\MIMWAL-2.18.1110.0\src\Scripts\EncryptData_xxxx.ps1:45 char:5
    +     $decryptedData = [MicrosoftServices.IdentityManagement.WorkflowAc ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : CryptographicException

    Exception calling "ConvertToUnsecureString" with "1" argument(s): "Value cannot be null.
    Parameter name: secret"
    At E:\MIMWAL-2.18.1110.0\src\Scripts\EncryptData_xxxx.ps1:49 char:5
    +     $plainText = [MicrosoftServices.IdentityManagement.WorkflowActivi ...
    +     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : ArgumentNullException

    TestCertificateBasedEncryptionDecryption :
    Encryption and Decryption test using certificate '5D48CF33494CDE412DE69F58D67B22003E087B39' failed!

    Steps i followed

    a- New-SelfSignedCertificate -Type Custom -Provider "Microsoft Strong Cryptographic Provider" -DnsName "" -CertStoreLocation "Cert:\LocalMachine\My"

    Sucessfully created.

    b- Changed all the parameters in the encryptdata ps file by running the following commands

     .\gacutil.exe -l | findstr WorkflowActivityLibrary

    updating the correct thumbprint

    c- Updating the password i want to encrypt.

    d- Running the command encryptdata_xx.ps1 gives the error.

    Powershell version is  4.6 or above. Not sure what the error is as the output file is correctly generated with the correct format

    Friday, February 8, 2019 1:01 PM