Steve O. Ams, Jr. Ego Magnus Numen
Ego Magnus Numen

Epic Mnemonic Decryption

The attached EpicRequest class is an example of the decryption process required to ascertain an Epic Hyperspace Mnemonic Encryption service’s decrypted value.

class EpicRequest
    {
        public string Decrypt(string encryptedUser)
        {
            var  xusr = "";
            try
            {
                var keyValue = WebConfigurationManager.AppSettings["SharedSecret"];        
                var userByte = new byte[32];
                Array.Copy(Encoding.UTF8.GetBytes(encryptedUser), userByte, 0);
                xusr = Decryptor(encryptedUser, keyValue);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error: {0}", e.Message);
            }
            return xusr;
        }
        public static string Decryptor(string TextToDecrypt, string strKey)
        {
            byte[] EncryptedBytes = Convert.FromBase64String(TextToDecrypt);
            string strIV = "0000000000000000";          
            AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider();
            aesProvider.BlockSize = 128;
            aesProvider.KeySize = 128;

            aesProvider.Key = string2byte(strKey);
            aesProvider.IV = string2byte(strIV);
            aesProvider.Padding = PaddingMode.PKCS7;
            aesProvider.Mode = CipherMode.ECB;

            ICryptoTransform cryptoTransform = aesProvider.CreateDecryptor(aesProvider.Key, aesProvider.IV);
            byte[] DecryptedBytes = cryptoTransform.TransformFinalBlock(EncryptedBytes, 0, EncryptedBytes.Length);
            return Encoding.UTF8.GetString(DecryptedBytes);
        }

        public static byte[] string2byte(string newString)
        {
            char[] CharArray = newString.ToCharArray();
            byte[] ByteArray = new byte[CharArray.Length];

            for (int i = 0; i < CharArray.Length; i++)
            {
                ByteArray[i] = Convert.ToByte(CharArray[i]);
            }
            return ByteArray;
        }

        public static byte[] stringToByte(string newString, int charLength)
        {
            char[] CharArray = newString.ToCharArray();
            byte[] ByteArray = new byte[charLength];
            for (int i = 0; i < CharArray.Length; i++)
            {
                ByteArray[i] = Convert.ToByte(CharArray[i]);
            }
            return ByteArray;
        }
    }