public void EncodeDecodeData() { var cryptoProvider = new EncodingCryptoProvider(); string encodedCipherText = cryptoProvider.EncryptAndEncode(TestData); Assert.AreEqual(TestData, cryptoProvider.DecodeAndDecrypt(encodedCipherText)); }
/// <summary> /// Called after upgrade. /// </summary> public static void Upgrade(string tenantName) { using (new SecurityBypassContext()) { var crypto = new EncodingCryptoProvider(); using (new GlobalAdministratorContext()) { /* * ImapServerSettings has been moved to the global tenant only. Not sure if we need to move this elsewhere as here it will be run for each tenant */ Factory.SecuredDataSaveHelper.UpgradeField( ImapServerSettingsEventTarget.SecureIdContext, ImapServerSettings.ImapServerSettings_Type, ImapServerSettings.ImapPassword_Field, ImapServerSettings.ImapPasswordSecureId_Field, (s) => crypto.DecodeAndDecrypt(s)); } using (new TenantAdministratorContext(tenantName)) { Factory.SecuredDataSaveHelper.UpgradeField( EmailServerSettingsEventTarget.SecureIdContext, TenantEmailSetting.TenantEmailSetting_Type, TenantEmailSetting.SmtpPassword_Field, TenantEmailSetting.SmtpPasswordSecureId_Field, (s) => crypto.DecodeAndDecrypt(s)); // identityProvider OidcClientSecret Factory.SecuredDataSaveHelper.UpgradeField( OidcIdentityProviderEventTarget.SecureIdContext, OidcIdentityProvider.OidcIdentityProvider_Type, OidcIdentityProvider.OidcClientSecret_Field, OidcIdentityProvider.OidcClientSecretSecureId_Field, (s) => crypto.DecodeAndDecrypt(s) ); } } }
/// <summary> /// Validates the state of the authentication. /// </summary> /// <param name="state">The state.</param> /// <returns>OpenIdConnectAuthorizationState.</returns> /// <exception cref="System.ArgumentNullException">state</exception> /// <exception cref="AuthenticationException">The authorization state is invalid.</exception> public OpenIdConnectAuthorizationState ValidateAuthState(string state) { if (string.IsNullOrWhiteSpace(state)) { throw new ArgumentNullException(nameof(state)); } OpenIdConnectAuthorizationState authState; // Decrypt, decode and deserialize try { var cryptoProvider = new EncodingCryptoProvider(); var decryptedState = cryptoProvider.DecodeAndDecrypt(state); authState = JSON.Deserialize <OpenIdConnectAuthorizationState>(decryptedState); } catch (Exception exception) { throw new AuthenticationException("The authorization state is invalid.", exception); } return(ValidateAuthState(authState)); }