The Decrypt method decrypts the input string using the encryption key provided. The input is converted to bytes and then passed to the TripleDESCryptoServiceProvider object. The TripleDESCryptoServiceProvider object is set to use the ECB cipher mode, with a PKCS7 padding scheme. The ICryptoTransform object is created, and the TransformFinalBlock method is called, passing in the incoming bytes as well as the length of the input bytes. The TripleDESCryptoServiceProvider object is cleared after the transform is complete.

    using System;
    using System.Security.Cryptography;
    using System.Text;
    /// <summary>
    /// Dencrypts input string
    /// </summary>
    /// <param name="input">string to dencrypt</param>
    /// <returns>dencrypted result</returns>
    public static string Decrypt(string input, string encryption_key)
      byte[] inputArray = Convert.FromBase64String(input);
      TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
      tripleDES.Key = UTF8Encoding.UTF8.GetBytes(encryption_key);
      tripleDES.Mode = CipherMode.ECB;
      tripleDES.Padding = PaddingMode.PKCS7;
      ICryptoTransform cTransform = tripleDES.CreateDecryptor();
      byte[] resultArray = cTransform.TransformFinalBlock(inputArray, 0, inputArray.Length);
      return UTF8Encoding.UTF8.GetString(resultArray);
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.