public void StringEncryptorEncryptDecryptTest() { const string initial = "THESTRING"; var encrypted = StringEncryptor.Encrypt(initial); var decrypted = StringEncryptor.Decrypt(encrypted); Assert.IsFalse(initial == encrypted); Assert.IsTrue(initial == decrypted); }
public static void SetSaveData <T>(T obj, string name) { var json = JsonUtility.ToJson(obj); var jsonEncrypt = StringEncryptor.Encrypt(json); var path = PreparePath(name); File.WriteAllText(path, jsonEncrypt); }
public override string ReadData() { var data = base.ReadData(); if (!StringEncryptor.IsEncrypted(data)) { data = StringEncryptor.Encrypt(data); } return(StringEncryptor.Decrypt(data)); }
public void StringEncryptor_GivenCorrectKey_DecryptsMessage() { string plainText = "Mary had a little lamb."; string key = "Behold, I've become the destroyer of worlds."; string encryptedText = StringEncryptor.Encrypt(plainText, key); string decryptedText = StringEncryptor.Decrypt(encryptedText, key); decryptedText.Should().Be(plainText); }
public void StringEncryptor_GivenIncorrectKey_CannotDecryptMessage() { string plainText = "Mary had a little lamb."; string key = "Behold, I've become the destroyer of worlds."; string encryptedText = StringEncryptor.Encrypt(plainText, key); Action act = () => StringEncryptor.Decrypt(encryptedText, "wrong key"); act.ShouldThrow <CryptographicException>(); }
public string EncodePermalink(string link, bool rooted) { HttpRequest request = HttpContext.Current.Request; StringEncryptor enc = new StringEncryptor(); if (rooted) { string appPath = request.ApplicationPath; if (appPath.Equals("/")) appPath = String.Empty; return String.Format("{0}://{1}{2}/default.aspx?_link={3}", request.Url.Scheme, request.Url.Authority, appPath, HttpUtility.UrlEncode(enc.Encrypt(link))); } else { string[] linkSegments = link.Split('?'); string arguments = String.Empty; if (linkSegments.Length > 1) arguments = linkSegments[1]; return String.Format("{0}?_link={1}", linkSegments[0], HttpUtility.UrlEncode(enc.Encrypt(arguments))); } }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { var stringValue = value as string; if (string.IsNullOrEmpty(stringValue)) { writer.WriteNull(); return; } var encryptedValue = StringEncryptor.Encrypt(stringValue, _passphrase); writer.WriteValue(encryptedValue); }
protected override void CompleteDialogExtention() { //stucture this and use app to reference in the test project // save to the setting exists in the settings folder then get it var folder = ApplicationController.SettingsPath; FileUtility.CheckCreateFolder(folder); var xmlString = DataContractSerializeObject(EnteredObject); var encrypt = StringEncryptor.Encrypt(xmlString); FileUtility.CheckCreateFolder(SaveTo.SaveToFolder.FolderPath); FileUtility.WriteToFile(SaveTo.SaveToFolder.FolderPath, typeof(T).Name + ".xml", encrypt); CompletionMessage = "The Object Has Been Encrypted"; }
//------------------------------------------------------------------------------------------------- //--- Create an Encrypted String out of an Infoblock object //------------------------------------------------------------------------------------------------- public static string EncodeToString(InfoBlock anInfoBlock) { string myEncryptedString = ""; string myString; theJsonSerializerSettings.TypeNameHandling = TypeNameHandling.None; try { myString = JsonConvert.SerializeObject(anInfoBlock, theJsonSerializerSettings); myEncryptedString = myStringEncryptor.Encrypt(myString); } catch (Exception ex) { } return(myEncryptedString); }
public void Save(int _saveSlot = 0) { string jsonText = JsonUtility.ToJson(m_saveData); if (Application.platform == RuntimePlatform.WebGLPlayer) { //WebGLの時はPlayerPrefsを使用 PlayerPrefs.SetString(SaveKey + _saveSlot.ToString("0"), StringEncryptor.Encrypt(jsonText)); } else { File.WriteAllText(GetSaveFilePath(_saveSlot), StringEncryptor.Encrypt(jsonText)); } if (m_isCheckLog) { Debug.Log(_saveSlot.ToString("0") + "番のスロットに現在のデータを保存しました。"); } }
public void EncryptMethod_On_ASD_Return_BTE_WithKey_1() { // AAA // Arrange const string str = "ASD"; const string expected_result = "BTE"; const int key = 1; // Act var actual_result = StringEncryptor.Encrypt(str, key); // Assert Assert.AreEqual(expected_result, actual_result, $"Ошибка {str} кодирования"); //StringAssert.Matches(); //CollectionAssert. if (expected_result != actual_result) { throw new AssertFailedException("Ошибка в методе кодирования данных"); } }
protected void processButton_Click(object sender, EventArgs e) { string stringToEncrypt = encryptBox.Text; string stringToDecrypt = decryptBox.Text; string encryptedString = StringEncryptor.Encrypt(stringToEncrypt); if (stringToDecrypt == "") { stringToDecrypt = encryptedString; } string decryptedString = StringEncryptor.Decrypt(stringToDecrypt); StringBuilder sb = new StringBuilder(); sb.Append("Encrypted data: "); sb.Append(encryptedString); sb.Append("<br />Decrypted data: "); sb.Append(decryptedString); result.Text = sb.ToString(); }
public string SaveDataToJson(RankingData _data) { return(StringEncryptor.Encrypt(JsonUtility.ToJson(_data))); }
public static Password CreateFromRawPassword(string rawPassword) { return(new Password(StringEncryptor.Encrypt(rawPassword))); }
public Password(string password, bool isEncrypted, bool encrypt) { EncryptPassword = encrypt; _password = EncryptPassword && !isEncrypted?StringEncryptor.Encrypt(password) : password; }
public override void WriteData(string data) { base.WriteData(StringEncryptor.Encrypt(data)); }
public string EncodePermalink(string link, bool rooted) { HttpRequest request = HttpContext.Current.Request; StringEncryptor enc = new StringEncryptor(); if (rooted) { string appPath = request.ApplicationPath; if (appPath.Equals("/")) { appPath = String.Empty; } return(String.Format("{0}://{1}{2}/default.aspx?_link={3}", request.Url.Scheme, request.Url.Authority, appPath, HttpUtility.UrlEncode(enc.Encrypt(link)))); } else { string[] linkSegments = link.Split('?'); string arguments = String.Empty; if (linkSegments.Length > 1) { arguments = linkSegments[1]; } return(String.Format("{0}?_link={1}", linkSegments[0], HttpUtility.UrlEncode(enc.Encrypt(arguments)))); } }