Login / Register
▼
Binary Fortress
Binary Fortress Software
CheckCentral
ClipboardFusion
CloudShow
DisplayFusion
FileSeek
HashTools
LogFusion
Notepad Replacer
Online Base64 Decoder
Online Base64 Encoder
Online JSON Formatter
ShellSend
TrayStatus
VoiceBot
WallpaperFusion
Window Inspector
More Apps...
DisplayFusion
CheckCentral
CloudShow
ClipboardFusion
FileSeek
VoiceBot
WallpaperFusion
▼
Download
Download
Change Log
Download Beta
Beta Change Log
License (EULA)
▼
Features
Features
HotKeys
Macros
Triggers
Clipboard Syncing
Clipboard Manager
Languages
Free vs Pro
Purchase
Screenshots
Apps
▼
Online
Online
Recent Items
Pinned Items
▼
Help
Help Guide
FAQ
Discussions
Contact Us
Find My License
Mailing Address
Advanced Settings
Macros
Languages
Clipboard
Fusion
WARNING: You currently have Javascript disabled!
This website will not function correctly without Javascript enabled.
Title
Message
OK
Confirm
Yes
No
AES Encryption\Decryption
Return to ClipboardFusion Macros
Description
This script encrypts and decrypts text using the AES256 algorithm. For security, it doesn't use the clipboard at all.
Language
C# (.Net)
Minimum Version
5.6+
Created By
jackz98
Contributors
-
Date Created
Oct 8, 2019
Date Last Modified
Feb 18, 2020
Macro Code
Copy
Select All
Toggle Line Wrapping
using System; using System.IO; using System.IO.Compression; using System.Security.Cryptography; using System.Text; /// <summary> /// C# AES256 by jackz98 /// </summary> public static class ClipboardFusionHelper { private static readonly int Iterations = 10025; private static byte[] CompressBytes(byte[] bytes) { using (MemoryStream compressStream = new MemoryStream()) { using (var zipStream = new GZipStream(compressStream, CompressionMode.Compress)) zipStream.Write(bytes, 0, bytes.Length); return compressStream.ToArray(); } } private static byte[] DecompressBytes(byte[] bytes) { using (var compressStream = new MemoryStream(bytes)) { using (var zipStream = new GZipStream(compressStream, CompressionMode.Decompress)) { using (var resultStream = new MemoryStream()) { zipStream.CopyTo(resultStream); return resultStream.ToArray(); } } } } public static byte[] D(byte[] input, string password, bool enc) { using (var aes = new AesManaged() { KeySize = 256, BlockSize = 128, Mode = CipherMode.CBC, Padding = PaddingMode.PKCS7 }) { byte[] salt = new byte[16]; if(enc) new RNGCryptoServiceProvider().GetBytes(salt); else Array.Copy(input, 0, salt, 0, salt.Length); using (var generator = new Rfc2898DeriveBytes(password, salt, Iterations)) { aes.IV = generator.GetBytes(16); aes.Key = generator.GetBytes(32); ICryptoTransform eng; if (enc) eng = aes.CreateEncryptor(); else eng = aes.CreateDecryptor(); using (var outStream = new MemoryStream()) { if(enc) outStream.Write(salt, 0, salt.Length); using (var cryptoStream = new CryptoStream(outStream, eng, CryptoStreamMode.Write)) using (var binaryWriter = new BinaryWriter(cryptoStream)) { if(enc) binaryWriter.Write(CompressBytes(input)); else binaryWriter.Write(input, salt.Length, input.Length - salt.Length); } if(enc) return outStream.ToArray(); else return DecompressBytes(outStream.ToArray()); } } } } private static string AddNewLine(string s) { var sb = new StringBuilder(s); for (int i = (s.Length / 64) * 64; i >= 64; i -= 64) sb.Insert(i, Environment.NewLine); return sb.ToString(); } public static string ProcessText(string text) { // your code goes here text = BFS.Clipboard.CopyText(); BFS.ClipboardFusion.PauseClipboardListener(); if (text != null && text.Length >= 0) { string res; string a = BFS.Dialog.GetUserInputListViewWithFilter("AES Encryption/Decryption", new string[2] { "Encryption", "Decryption" }); if (a == "Encryption") { string pass = BFS.Dialog.GetUserInput("Encryption: Input your password here!", ""); if (pass != "") { res = AddNewLine(System.Convert.ToBase64String(D(System.Text.Encoding.UTF8.GetBytes(text), pass, true))); BFS.Clipboard.PasteText(res); } } else if (a != "") { string pass = BFS.Dialog.GetUserInput("Decryption: Input your password here!", ""); if (pass != "") { try { res = Encoding.UTF8.GetString(D(System.Convert.FromBase64String(text), pass, false)); BFS.Clipboard.PasteText(res); } catch (Exception) { BFS.Dialog.ShowMessageError("Decryption Failed: malformated text, corrupted message or wrong password!"); } } } } BFS.Clipboard.Clear(); BFS.ClipboardFusion.ResumeClipboardListener(); return null; } }
Copyright © 2007-2021 Binary Fortress Software
•
News
•
Discussions
•
FAQ
•
Support
•
Privacy
•
ToS
•
Get Binary Fortress Merch