Decrypt String

    0

    15

    Bernat Nosas

    decrypt

    Static function to dencrypt a string passed as parameter. It requires a dencription key as well.

    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);
      tripleDES.Clear();
      return UTF8Encoding.UTF8.GetString(resultArray);
    }
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Explore
    • Cookbooks
    • Playground
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.