/// <summary> /// アカウント情報の読み出し /// </summary> /// <returns></returns> public Account Load() { try { Account = EncryptionSerializer.Decrypt <Account>(EncryptionSerializer.DefaultFilePath); } catch { Account = new Account("", "", ""); } return(Account); }
public async Task SerializeDeserialize() { const string toEncryptAndSerialize = "something to encrypt and serialize"; var encryptorDecryptor = new AesEncryptorDecryptor(); var headerGenerator = new ShaHeaderGenerator(); var serializer = new EncryptionSerializer <string>(new JsonSerializer <string>(), new ShaAesEncryptor(encryptorDecryptor, headerGenerator), new ShaAesDecryptor(encryptorDecryptor, headerGenerator), "sample passphrase".ToSecureString(), "sample salt"); using (var memoryStream = new MemoryStream()) { await serializer.SerializeAsync(memoryStream, toEncryptAndSerialize); memoryStream.Position = 0; var actual = await serializer.DeserializeAsync(memoryStream); Assert.That(actual, Is.EqualTo(toEncryptAndSerialize)); } }
/// <summary> /// アカウント情報の保存 /// </summary> public void Save() { EncryptionSerializer.Encrypt <Account>(Account, EncryptionSerializer.DefaultFilePath); }