public static byte[] Encrypt(byte[] plainbytes, bool compress) { byte[] buffer; byte compressFlag; if (plainbytes.Length > MINIMUM_LENGTH_FOR_COMPRESSION) { compressFlag = Convert.ToByte(COMPRESSED); buffer = CompressionHelper.Deflate(plainbytes); } else { compressFlag = Convert.ToByte(NOTCOMPRESSED); buffer = plainbytes; } byte[] encryptedBytes = Obviex.CipherLite.Rijndael.Encrypt(CompressionHelper.BytesToString(buffer), SettingsCache.GetSetting("Security.Cipher.PassPhrase"), SettingsCache.GetSetting("Security.Cipher.InitVector"), KEY_SIZE, PASSWORD_ITERATIONS, SettingsCache.GetSetting("Security.Cipher.Salt"), HASH_ALGORITHM); byte[] toReturn = new byte[encryptedBytes.Length + 1]; int index = 0; toReturn[index++] = compressFlag; for (int i = 0; i < encryptedBytes.Length; i++) { toReturn[index++] = encryptedBytes[i]; } return(toReturn); }
public async Task ExecuteAsync_ReceivedConfig_Updated_Correctly() { var config = GetValidConfig(); _mockConfigurationStorageClient.Setup(client => client.ExecuteAsync(It.IsAny <string>(), _token)).ReturnsAsync(config); SettingsCache <int> ints = null; SettingsCache <bool> bools = null; SettingsCache <string> strings = null; _mockSettingsCacheManager.Setup( manager => manager.ReloadSettingsCache(It.IsAny <SettingsCache <int> >(), It.IsAny <SettingsCache <bool> >(), It.IsAny <SettingsCache <string> >())) .Callback((SettingsCache <int> i, SettingsCache <bool> b, SettingsCache <string> s) => { ints = i; bools = b; strings = s; }); await _configurationUpdaterJob.ExecuteAsync("app", _token); _mockSettingsCacheManager.Verify( manager => manager.ReloadSettingsCache(It.IsAny <SettingsCache <int> >(), It.IsAny <SettingsCache <bool> >(), It.IsAny <SettingsCache <string> >()), Times.Once); strings.GetSetting("string-item", _handler).ShouldBe("abcd"); ints.GetSetting("int-item", _handler).ShouldBe(123); bools.GetSetting("bool-item", _handler).ShouldBe(true); }
public static string Decrypt(byte[] cipherbytes, bool compress) { byte[] buffer = new byte[cipherbytes.Length - 1]; int index = 0; for (int i = 1; i < cipherbytes.Length; i++) { buffer[index++] = cipherbytes[i]; } string decrypted = Obviex.CipherLite.Rijndael.Decrypt(buffer, SettingsCache.GetSetting("Security.Cipher.PassPhrase"), SettingsCache.GetSetting("Security.Cipher.InitVector"), KEY_SIZE, PASSWORD_ITERATIONS, SettingsCache.GetSetting("Security.Cipher.Salt"), HASH_ALGORITHM); if (cipherbytes[0] == COMPRESSED) { return(CompressionHelper.Inflate(decrypted)); } else { return(decrypted); } }