コード例 #1
0
        static byte[] ZipEncrypt(LocalEvent e, string secretKey)
        {
            var bytes      = Encoding.UTF8.GetBytes(e.Json());
            var compressed = bytes.Compress();
            var encrypted  = BytesCrypto.EncryptFromBytes(secretKey, compressed);

            return(encrypted);
        }
コード例 #2
0
        void Save(UserConfig user)
        {
            var bytes      = BytesCrypto.Encrypt(_password, JsonConvert.SerializeObject(user));
            var userFolder = Scrambler.Obfuscate(user.Username, _password);
            var dirPath    = "../sndc";
            var filePath   = $"{dirPath}/{userFolder}".ToLowerInvariant();

            File.WriteAllBytes(filePath, bytes);
        }
コード例 #3
0
 public LocalEvent GetEvent(string secretKey)
 {
     if (_event == null)
     {
         var decrypted    = BytesCrypto.DecryptToBytes(secretKey, ZipEncryptedData);
         var decompressed = decrypted.Decompress();
         var json         = Encoding.UTF8.GetString(decompressed);
         _event = (LocalEvent)json.Parse(AssemblyQualifiedName);
     }
     return(_event);
 }
コード例 #4
0
        public UserConfig CreateOrDecrypUserConfig()
        {
            var userFolder = Scrambler.Obfuscate(_username, _password);
            var dirPath    = "../sndc";
            var filePath   = $"{dirPath}/{userFolder}".ToLowerInvariant();

            if (!File.Exists(filePath))
            {
                var config = CreateUserConfig();
                var bytes  = BytesCrypto.Encrypt(_password, JsonConvert.SerializeObject(config));
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
                File.WriteAllBytes(filePath, bytes);
                return(config);
            }
            var data = File.ReadAllBytes(filePath);
            var json = BytesCrypto.Decrypt(_password, data);

            return(JsonConvert.DeserializeObject <UserConfig>(json));
        }