Unity C#スクリプトAES暗号解読を実現

1326 ワード

   /// 
    /// AES 
    /// 
    ///  
    ///  
    /// 
    public static byte[] Encrypt(byte[] toEncryptArray, string key)
    {
        byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);        
        RijndaelManaged rDel = new RijndaelManaged();
        rDel.Key = keyArray;
        rDel.Mode = CipherMode.ECB;
        rDel.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = rDel.CreateEncryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
        return resultArray;
    }

    /// 
    /// AES 
    /// 
    ///  
    ///  
    /// 
    public static byte[] Decrypt(byte[] toEncryptArray, string key)
    {
        byte[] keyArray = UTF8Encoding.UTF8.GetBytes(key);        
        RijndaelManaged rDel = new RijndaelManaged();
        rDel.Key = keyArray;
        rDel.Mode = CipherMode.ECB;
        rDel.Padding = PaddingMode.PKCS7;
        ICryptoTransform cTransform = rDel.CreateDecryptor();
        byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
        return resultArray;
    }