Ejemplo n.º 1
0
        /// <summary>
        /// Does the actual saving.
        /// </summary>
        public override void Close()
        {
            // save the file to the filestream
            FileStream fs = new FileStream(Filename, FileMode.Create);

            if (Encryption == EncryptionType.AES)
            {
                fs.Write(AESProvider.Encrypt(Text.ToArray()), 0, Text.Count);
            }
            if (Encryption == EncryptionType.ASCII)
            {
                fs.Write(Utilities.StringToByte(ASCIIProvider.Encrypt(Utilities.ByteToString(Text.ToArray()))), 0, Text.Count);
            }
            if (Encryption == EncryptionType.DES)
            {
                fs.Write(DESProvider.Encrypt(Text.ToArray()), 0, Text.Count);
            }
            if (Encryption == EncryptionType.L1F3)
            {
                fs.Write(L1F3Provider.Encrypt(Utilities.ByteToString(Text.ToArray())), 0, Text.Count);
            }
            if (Encryption == EncryptionType.RC2)
            {
                fs.Write(RC2Provider.Encrypt(Text.ToArray()), 0, Text.Count);
            }
            if (Encryption == EncryptionType.Rijndael)
            {
                fs.Write(RijndaelProvider.Encrypt(Text.ToArray()), 0, Text.Count);
            }
            if (Encryption == EncryptionType.RSA)
            {
                fs.Write(RSAProvider.Encrypt(Text.ToArray()), 0, Text.Count);
            }
            if (Encryption == EncryptionType.TripleDES)
            {
                fs.Write(TripleDESProvider.Encrypt(Text.ToArray()), 0, Text.Count);
            }
            if (Encryption == EncryptionType.Xor)
            {
                fs.Write(Utilities.StringToByte(XorProvider.Encrypt(Utilities.ByteToString(Text.ToArray()))), 0, Text.Count);
            }
            fs.Close();
            base.Close();
        }
Ejemplo n.º 2
0
        public static LuaValue Encrypt(LuaValue[] args)
        {
            string encType = (args[0] as LuaString).Text.ToLower();
            string _in     = args[1].ToString();

            if (encType == "aes")
            {
                return(new LuaString(AESProvider.Encrypt(_in)));
            }
            else if (encType == "ascii")
            {
                // encrypt with first byte of key
                return(new LuaString(ASCIIProvider.Encrypt(_in)));
            }
            if (encType == "des")
            {
                return(new LuaString(DESProvider.Encrypt(_in)));
            }
            if (encType == "rc2")
            {
                return(new LuaString(RC2Provider.Encrypt(_in)));
            }
            if (encType == "rijndael")
            {
                return(new LuaString(RijndaelProvider.Encrypt(_in)));
            }
            if (encType == "rsa")
            {
                return(new LuaString(RSAProvider.Encrypt(_in)));
            }
            if (encType == "tripledes")
            {
                return(new LuaString(TripleDESProvider.Encrypt(_in)));
            }
            if (encType == "xor")
            {
                return(new LuaString(XorProvider.Encrypt(_in)));
            }
            throw new Exception("Unsuported encryption '" + encType + "'!");
        }