SHOW:
|
|
- or go back to the newest paste.
| 1 | using System; | |
| 2 | using System.Collections.Generic; | |
| 3 | using System.IO; | |
| 4 | using System.Linq; | |
| 5 | using System.Runtime.Serialization.Formatters.Binary; | |
| 6 | using System.Security.Cryptography; | |
| 7 | using System.Text; | |
| 8 | using System.Threading.Tasks; | |
| 9 | ||
| 10 | namespace BSW_Encode | |
| 11 | {
| |
| 12 | class Program | |
| 13 | {
| |
| 14 | private static readonly string IV_VALUE = "8charlie7volpe87"; | |
| 15 | private static readonly string JSON_ENCRYPTION_KEY = "C_H8A#R(L0I!E-09V3O]L)/9P)-E390+"; | |
| 16 | ||
| 17 | static void Main(string[] args) | |
| 18 | {
| |
| 19 | FileStream fs = File.Open("ILYCS.bsw.json", FileMode.Open);
| |
| 20 | StreamReader sr = new StreamReader(fs); | |
| 21 | String input_str = sr.ReadToEnd(); | |
| 22 | WriteBinary("ILYCS.bsw", input_str);
| |
| 23 | ||
| 24 | ||
| 25 | } | |
| 26 | public static void WriteBinary(string a_localPath, string a_json) | |
| 27 | {
| |
| 28 | BinaryFormatter binaryFormatter = new BinaryFormatter(); | |
| 29 | FileStream fileStream1 = File.Create(a_localPath); | |
| 30 | byte[] numArray1 = Encrypt(a_json, JSON_ENCRYPTION_KEY); | |
| 31 | FileStream fileStream2 = fileStream1; | |
| 32 | byte[] numArray2 = numArray1; | |
| 33 | binaryFormatter.Serialize((Stream)fileStream2, (object)numArray2); | |
| 34 | fileStream1.Close(); | |
| 35 | } | |
| 36 | ||
| 37 | public static byte[] Encrypt(string a_original, string a_key) | |
| 38 | {
| |
| 39 | byte[] numArray = (byte[])null; | |
| 40 | byte[] bytes1 = Encoding.ASCII.GetBytes(IV_VALUE); | |
| 41 | byte[] bytes2 = Encoding.ASCII.GetBytes(a_key); | |
| 42 | using (RijndaelManaged rijndaelManaged = new RijndaelManaged()) | |
| 43 | {
| |
| 44 | rijndaelManaged.Key = bytes2; | |
| 45 | rijndaelManaged.IV = bytes1; | |
| 46 | numArray = EncryptStringToBytes(a_original, rijndaelManaged.Key, rijndaelManaged.IV); | |
| 47 | } | |
| 48 | return numArray; | |
| 49 | } | |
| 50 | private static byte[] EncryptStringToBytes(string plainText, byte[] Key, byte[] IV) | |
| 51 | {
| |
| 52 | if (plainText == null || plainText.Length <= 0) | |
| 53 | throw new ArgumentNullException(nameof(plainText)); | |
| 54 | if (Key == null || Key.Length == 0) | |
| 55 | throw new ArgumentNullException(nameof(Key)); | |
| 56 | if (IV == null || IV.Length == 0) | |
| 57 | throw new ArgumentNullException(nameof(IV)); | |
| 58 | using (RijndaelManaged rijndaelManaged = new RijndaelManaged()) | |
| 59 | {
| |
| 60 | rijndaelManaged.Key = Key; | |
| 61 | rijndaelManaged.IV = IV; | |
| 62 | ICryptoTransform encryptor = rijndaelManaged.CreateEncryptor(rijndaelManaged.Key, rijndaelManaged.IV); | |
| 63 | using (MemoryStream memoryStream = new MemoryStream()) | |
| 64 | {
| |
| 65 | using (CryptoStream cryptoStream = new CryptoStream((Stream)memoryStream, encryptor, CryptoStreamMode.Write)) | |
| 66 | {
| |
| 67 | using (StreamWriter streamWriter = new StreamWriter((Stream)cryptoStream)) | |
| 68 | streamWriter.Write(plainText); | |
| 69 | return memoryStream.ToArray(); | |
| 70 | } | |
| 71 | } | |
| 72 | } | |
| 73 | } | |
| 74 | } | |
| 75 | } |