// Returns Success public bool Decrypt(IMessage message) { var metadata = message.GetMetadata(); if (metadata.Encrypted) { message.Body = EncryptionProvider.Decrypt(message.Body).Array; metadata.Encrypted = false; metadata.CustomFields[Constants.HeaderForEncrypted] = false; if (metadata.CustomFields.ContainsKey(Constants.HeaderForEncryption)) { metadata.CustomFields.Remove(Constants.HeaderForEncryption); } if (metadata.CustomFields.ContainsKey(Constants.HeaderForEncryptDate)) { metadata.CustomFields.Remove(Constants.HeaderForEncryptDate); } return(true); } return(false); }
public void EncryptionProvider_Decrypt_ReturnsExpectedPlaintext() { EncryptionProvider cipher = new EncryptionProvider(validKey); string plaintext = cipher.Decrypt(validCiphertext, validNonce); Assert.AreEqual(validPlaintext, plaintext); }
public void EncryptionProvider_DecryptSuccessfullyDecryptsTheEncryptMethod() { EncryptionProvider cipher = new EncryptionProvider(validKey); string plaintext = cipher.Decrypt(validCiphertext, validNonce); Assert.AreEqual(validPlaintext, plaintext); }
public void MetroHmacSHA1Encryption_MarkerMetro_Failed() { string originalString = "MarkerMetro"; string key = "encryptionKey"; Assert.ThrowsException <Exception>(() => EncryptionProvider.Encrypt(originalString, key, HashFunctionType.SHA1)); Assert.ThrowsException <Exception>(() => EncryptionProvider.Decrypt(originalString, key, HashFunctionType.SHA1)); }
public void EncryptRoundTripv1(string data) { EncryptionProvider p = new EncryptionProvider(); var cert = this.certificateProvider.CreateSelfSignedCert("test", CertificateProvider.LithnetAccessManagerPasswordEncryptionEku); string encrypted = p.Encrypt(cert, data, 1); string decrypted = p.Decrypt(encrypted, _ => cert); Assert.AreEqual(data, decrypted); }
public static string LoadSetting(string key) { var encrypted = ApplicationData.Current.LocalSettings.Values[key] as string; if (encrypted == null) { return(null); } return(EncryptionProvider.Decrypt(encrypted, CurrentApp.AppId.ToString())); }
public void EncryptRoundTripv2(string data) { EncryptionProvider p = new EncryptionProvider(); var cert = this.certificateProvider.CreateSelfSignedCert("test"); string encrypted = p.Encrypt(cert, data, 2); string decrypted = p.Decrypt(encrypted, _ => cert); Assert.AreEqual(data, decrypted); }
public async Task <IActionResult> Test(TestTemplateDto template) { Mail mail; try { mail = context.Set <Mail>() .Where(x => x.User.Id == user.Id && x.Id == template.MailId) .First(); } catch (Exception ex) { throw new BusinessException("mail-not-found", "The provided mail was not found", ex); } var stubble = new StubbleBuilder().Build(); var from = new MailAddress(mail.EmailAddress); var to = new MailAddress(template.Recipient.Email); var password = encryption.Decrypt(mail.Password, template.Secret); var subject = await stubble.RenderAsync(template.Subject, template.Recipient.Args); var body = await stubble.RenderAsync(template.Content, template.Recipient.Args); var message = new MailMessage(from, to) { Subject = subject, Body = body, BodyEncoding = Encoding.UTF8, IsBodyHtml = template.IsHtml }; using var smtp = new SmtpClient(mail.Host, mail.Port) { DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, EnableSsl = mail.EnableSsl, Credentials = new NetworkCredential(mail.EmailAddress, password) }; await smtp.SendMailAsync(message); return(Ok()); }
public void MetroEncryptionProvider_EncryptDecrypt_MD5_ShouldEqualOriginal() { string originalString = "MarkerMetro"; string key = "encryptionKey"; //test using MD5 algorithm string encryptedString = EncryptionProvider.Encrypt(originalString, key); string decryptedString = EncryptionProvider.Decrypt(encryptedString, key); Assert.IsTrue(originalString == decryptedString); }
/// <summary> /// Test EncryptionProvider HMACSHA256 encrypt and decrypt. /// </summary> public void MetroEncryptionProvider_EncryptDecrypt_HMACSHA256_ShouldEqualOriginal() { string originalString = "MarkerMetro"; string key = "encryptionKey"; //test using HMACSHA256 algorithm var encryptedString = EncryptionProvider.Encrypt(originalString, key, HashFunctionType.HMACSHA256, Encoding.UTF8.GetBytes("secret")); var decryptedString = EncryptionProvider.Decrypt(encryptedString, key, HashFunctionType.HMACSHA256, Encoding.UTF8.GetBytes("secret")); Assert.IsTrue(originalString == decryptedString); }
public static void Encryption(EncryptionProvider provider) { var cipher_s = provider.Encrypt("192.168.1.22 2323 foo bar", Encoding.ASCII); File.WriteAllText("credwin.txt", cipher_s + "\n", Encoding.ASCII); string read_s = File.ReadAllText("credwin.txt", Encoding.ASCII); string plaintext = provider.Decrypt(read_s, Encoding.ASCII); Console.WriteLine(plaintext); }
/// <summary> /// Decrypts message if the cert is present else returns raw string /// </summary> /// <param name="msgToDecrypt"></param> /// <returns></returns> public static string DecryptConfiguration(string msgToDecrypt, string thumbprint) { EncryptionProvider encryptionProvider = new EncryptionProvider(null); string decryptedMsg = msgToDecrypt; try { decryptedMsg = encryptionProvider.Decrypt(msgToDecrypt); } catch { } return(decryptedMsg); }
private byte[] DecryptRequest(byte[] requestData, EncryptionProvider crpyter) { try { return(crpyter.Decrypt(requestData)); } catch (CryptographicException ex) { if (CryptoError != null) { CryptoError(null, ex); } return(null); } }
public override string ReadToEnd() { var sb = new StringBuilder(); string line; try { while ((line = ReadLine()) != null) { sb.Append(EncryptionProvider.Decrypt(line, CurrentApp.AppId.ToString())); } } catch { } return(sb.ToString()); }
public static void EncryptionFromFile(EncryptionProvider provider) { string plainfile = "resources\\security-plain.xml"; string encryptedfile = "resources\\security-enc.xml"; string decryptedfile = "resources\\security-restored.txt"; if (System.Environment.OSVersion.Platform == PlatformID.Unix) { plainfile = plainfile.Replace("\\", "/"); encryptedfile = encryptedfile.Replace("\\", "/"); decryptedfile = decryptedfile.Replace("\\", "/"); } var credstring = File.ReadAllText(plainfile, Encoding.UTF8); var cipher_s = provider.Encrypt(credstring, Encoding.UTF8); File.WriteAllText(encryptedfile, cipher_s, Encoding.UTF8); string read_s = File.ReadAllText(encryptedfile, Encoding.UTF8); string plaintext = provider.Decrypt(read_s, Encoding.UTF8); Console.WriteLine(plaintext); File.WriteAllText(decryptedfile, plaintext + "\n", Encoding.UTF8); var doc = XDocument.Parse(plaintext); string module = "Click", store = "GRANTS", environment = "STAGING"; var el = doc.Descendants("Module").FirstOrDefault(e => e.Attribute("name").Value == module).Descendants("Store").FirstOrDefault(e => e.Attribute("name").Value == store).Descendants("Credential").FirstOrDefault(e => e.Attribute("environment").Value == environment); var username = el.Attribute("username").Value; var password = el.Attribute("password").Value; module = "Epic"; el = doc.Descendants("Module").FirstOrDefault(e => e.Attribute("name").Value == module).Descendants("Credential").FirstOrDefault(e => e.Attribute("environment").Value == environment); username = el.Attribute("username").Value; password = el.Attribute("password").Value; module = "OnBase"; el = doc.Descendants("Module").FirstOrDefault(e => e.Attribute("name").Value == module).Descendants("Credential").FirstOrDefault(e => e.Attribute("environment").Value == environment); username = el.Attribute("username").Value; password = el.Attribute("password").Value; }
public async Task <bool> CheckUserPassowrdExists(long Id, string oldPassword) { TUser user = await base.FindById(Id) as TUser; var result = false; if (user != null) { string userOldPassword = user.Password; if (_encryptionProvider.Decrypt(userOldPassword) == oldPassword) { result = true; } else { result = false; } } return(result); }
// Returns Success public bool Decrypt(Letter letter) { if (letter.LetterMetadata.Encrypted) { letter.Body = EncryptionProvider.Decrypt(letter.Body); letter.LetterMetadata.Encrypted = false; letter.LetterMetadata.CustomFields[Constants.HeaderForEncrypted] = false; if (letter.LetterMetadata.CustomFields.ContainsKey(Constants.HeaderForEncryption)) { letter.LetterMetadata.CustomFields.Remove(Constants.HeaderForEncryption); } if (letter.LetterMetadata.CustomFields.ContainsKey(Constants.HeaderForEncryptDate)) { letter.LetterMetadata.CustomFields.Remove(Constants.HeaderForEncryptDate); } return(true); } return(false); }
public Stream GetEpubPart(string partPath) { if (IsPartEncrypted(partPath)) { if (EncryptionProvider == null) { throw new ArgumentNullException("EncryptionProvider"); } var part = GetArchiveEntryBytes(partPath); if (part == null) { throw new Exception(string.Format("Epub part \"{0}\" doesn't exist", partPath)); } var decrypted = EncryptionProvider.Decrypt(part); return(new MemoryStream(decrypted)); } else { return(GetArchiveEntryStream(partPath)); } }
public FileContentResult DownloadPfxWithChain(Guid id) { DownloadPfxCertificateEntity cert = certificateRepository.Get <DownloadPfxCertificateEntity>(id); if (!cert.HasPrivateKey || cert.CertificateStorageFormat != CertificateStorageFormat.Pfx) { throw new Exception("No private key"); } X509Certificate2 x509 = new X509Certificate2(cert.Content, cipher.Decrypt(cert.PfxPassword, cert.PasswordNonce)); bool buildResult; X509Chain chain = new X509Chain(); X509Certificate2Collection x509Col = new X509Certificate2Collection(); try { chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck; buildResult = chain.Build(x509); } catch { throw new Exception("DownloadCertificateWithChain - Unable to build certificate chain"); } if (!buildResult) { throw new Exception("DownloadCertificateWithChain: Failed to build chain"); } byte[] chainBytes = x509Col.Export(X509ContentType.Pkcs12, cipher.Decrypt(cert.PfxPassword, cert.PasswordNonce)); return(new FileContentResult(chainBytes, pfxMimeType) { FileDownloadName = String.Format("{0}.pfx", cert.Thumbprint) }); }
public void EncryptionProvider_Decrypt_InvalidNonce_ThrowsException() { EncryptionProvider cipher = new EncryptionProvider(validKey); cipher.Decrypt(validCiphertext, invalidNonce); }
public static void Init( InitDelegate onInitComplete, string appId, HideUnityDelegate onHideUnity, string redirectUrl = null) { #if NETFX_CORE if (_client != null) { if (onInitComplete != null) { onInitComplete(); } return; } if (_web == null) { throw new MissingPlatformException(); } if (string.IsNullOrEmpty(appId)) { throw new ArgumentException("Invalid Facebook App ID"); } if (!string.IsNullOrEmpty(redirectUrl)) { _redirectUrl = redirectUrl; } _client = new FacebookClient(); _client.GetCompleted += HandleGetCompleted; AppId = _client.AppId = appId; _onHideUnity = onHideUnity; if (Settings.HasKey(TOKEN_KEY)) { AccessToken = EncryptionProvider.Decrypt(Settings.GetString(TOKEN_KEY), AppId); if (Settings.HasKey(EXPIRY_DATE)) { string expDate = EncryptionProvider.Decrypt(Settings.GetString(EXPIRY_DATE), AppId); Expires = DateTime.Parse(expDate, CultureInfo.InvariantCulture); } else { long expDate = Settings.GetLong(EXPIRY_DATE_BIN); Expires = DateTime.FromBinary(expDate); } _client.AccessToken = AccessToken; UserId = Settings.GetString(FBID_KEY); UserName = Settings.GetString(FBNAME_KEY); // verifies if the token has expired: if (DateTime.Compare(DateTime.UtcNow, Expires) > 0) { InvalidateData(); } //var task = TestAccessToken(); //task.Wait(); } if (onInitComplete != null) { onInitComplete(); } #else throw new PlatformNotSupportedException(""); #endif }
public void DecryptTest() { string userName = EncryptionProvider.Decrypt("bbZNJMF5fwxVk5F9ePLvkg=="); Assert.AreEqual(userName, "Ji-Feng Tsai"); }