예제 #1
0
        static public Stream DecryptFile(String filePath, String password)
        {
            byte[] bytesToBeDecrypted = File.ReadAllBytes(filePath);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);
            byte[] bytesDecrypted;

            passwordBytes  = SHA256.Create().ComputeHash(passwordBytes);
            bytesDecrypted = AES256.AES_Decrypt(bytesToBeDecrypted, passwordBytes);
            return(new MemoryStream(bytesDecrypted));
        }
예제 #2
0
        /*
        ** Encrypt and decrypt file
        */

        static public void EncryptFile(String filePath, String password)
        {
            byte[] bytesToBeEncrypted = File.ReadAllBytes(filePath);
            byte[] passwordBytes      = Encoding.UTF8.GetBytes(password);
            byte[] bytesEncrypted;

            passwordBytes  = SHA256.Create().ComputeHash(passwordBytes);
            bytesEncrypted = AES256.AES_Encrypt(bytesToBeEncrypted, passwordBytes);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
                File.WriteAllBytes(filePath, bytesEncrypted);
            }
        }
예제 #3
0
        // Url : Send the entity URL
        public static Stream GetDocumentStream(Boolean isPrivate, String Url, String encryptionKey)
        {
            Stream result;
            String fullUrl;

            fullUrl = GetFullDocumentUrl(Url);
            if (isPrivate)
            {
                result = AES256.DecryptFile(fullUrl, encryptionKey);
            }
            else
            {
                result = File.OpenRead(fullUrl);
            }
            result.Position = 0;
            return(result);
        }