Example #1
0
        public string encrypt(string text, string password)
        {
            core   c = new core();
            random r = new random();

            byte[] baPwd = Encoding.UTF8.GetBytes(password);

            // Hash the password with SHA256
            byte[] baPwdHash = SHA256Managed.Create().ComputeHash(baPwd);

            byte[] baText = Encoding.UTF8.GetBytes(text);

            byte[] baSalt      = r.GetRandomBytes();
            byte[] baEncrypted = new byte[baSalt.Length + baText.Length];

            // Combine Salt + Text
            for (int i = 0; i < baSalt.Length; i++)
            {
                baEncrypted[i] = baSalt[i];
            }
            for (int i = 0; i < baText.Length; i++)
            {
                baEncrypted[i + baSalt.Length] = baText[i];
            }

            baEncrypted = c.encrypt(baEncrypted, baPwdHash);

            string result = Convert.ToBase64String(baEncrypted);

            return(result);
        }
Example #2
0
        public void EncryptFile(string inputFile, string encryptedOutputFile, string password)
        {
            core c = new core();

            byte[] bytesToBeEncrypted = File.ReadAllBytes(inputFile);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);

            // Hash the password with SHA256
            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            byte[] bytesEncrypted = c.encrypt(bytesToBeEncrypted, passwordBytes);

            File.WriteAllBytes(encryptedOutputFile, bytesEncrypted);
        }
Example #3
0
        public string encrypt(string input, string password)
        {
            core c = new core();

            // Get the bytes of the string
            byte[] bytesToBeEncrypted = Encoding.UTF8.GetBytes(input);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);

            // Hash the password with SHA256
            passwordBytes = SHA256.Create().ComputeHash(passwordBytes);

            byte[] bytesEncrypted = c.encrypt(bytesToBeEncrypted, passwordBytes);

            string result = Convert.ToBase64String(bytesEncrypted);

            return(result);
        }