Created
November 14, 2018 06:23
-
-
Save yuiAs/1e9f4c6d0e44cd85417b98dcff46f1e3 to your computer and use it in GitHub Desktop.
Vカツのセーブデータを相互にごにょごにょ。Key/IVは自分で調べてね。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.IO; | |
| using System.Security.Cryptography; | |
| namespace vkatsu { | |
| public class VKCrypto | |
| { | |
| public static RijndaelManaged Rijndael { get; private set; } | |
| public int MaxBufferSize { get; set; } = 4*1024; | |
| public bool IsDebug { get; set; } = false; | |
| private byte[] _bk = null; | |
| private byte[] _bv = null; | |
| static VKCrypto() { | |
| Rijndael = new RijndaelManaged(); | |
| Rijndael.Padding = PaddingMode.PKCS7; | |
| Rijndael.Mode = CipherMode.CBC; | |
| Rijndael.KeySize = 256; | |
| // 現状 .Net coreだと AES128しか実装されてないので例外が出る | |
| Rijndael.BlockSize = 256; | |
| } | |
| public VKCrypto(string k, string v) { | |
| _bk = System.Text.Encoding.UTF8.GetBytes(k); | |
| _bv = System.Text.Encoding.UTF8.GetBytes(v); | |
| if ((_bk == null) || (_bv == null)) { | |
| throw new InvalidProgramException(); | |
| } else if (IsDebug) { | |
| Console.WriteLine("key: {0}", k); | |
| Console.WriteLine("iv : {0}", v); | |
| } | |
| } | |
| public void decode(string srcPath, string dstPath) { | |
| try { | |
| using (var src = new CryptoStream(new FileStream(srcPath, FileMode.Open, FileAccess.Read), Rijndael.CreateDecryptor(_bk, _bv), CryptoStreamMode.Read)) { | |
| using (var dst = new FileStream(dstPath, FileMode.Create, FileAccess.Write)) { | |
| var buf = new byte[MaxBufferSize]; | |
| var len = 0; | |
| while ((len = src.Read(buf, 0, buf.Length)) > 0) { | |
| dst.Write(buf, 0, len); | |
| } | |
| } | |
| } | |
| if (IsDebug) { | |
| Console.WriteLine("src: {0}", srcPath); | |
| Console.WriteLine("dst: {0}", dstPath); | |
| } | |
| } | |
| catch (Exception e) { | |
| Console.WriteLine(e.Message); | |
| } | |
| } | |
| public void encode(string srcPath, string dstPath) { | |
| try { | |
| using (var src = new FileStream(srcPath, FileMode.Open, FileAccess.Read)) { | |
| using (var dst = new CryptoStream(new FileStream(dstPath, FileMode.Create, FileAccess.Write), Rijndael.CreateEncryptor(_bk, _bv), CryptoStreamMode.Write)) { | |
| var buf = new byte[MaxBufferSize]; | |
| var len = 0; | |
| while ((len = src.Read(buf, 0, buf.Length)) > 0) { | |
| dst.Write(buf, 0, len); | |
| } | |
| } | |
| } | |
| if (IsDebug) { | |
| Console.WriteLine("src: {0}", srcPath); | |
| Console.WriteLine("dst: {0}", dstPath); | |
| } | |
| } | |
| catch (Exception e) { | |
| Console.WriteLine(e.Message); | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment