public static string Encrypt(string toEncrypt) { RSACryptoServiceProvider CSPRSA = null; string result; try { CSPRSA = new RSACryptoServiceProvider(); CSPRSA.FromXmlString(SAFSecurityKeys.loadKeysFromFile()); byte[] toEncryptArray = Encoding.UTF8.GetBytes(toEncrypt); result = Convert.ToBase64String(CSPRSA.Decrypt(toEncryptArray, false)); } catch { result = null; } finally { if (CSPRSA != null) { CSPRSA.Clear(); } } return(result); }
public static string ExpandSAFCore() { string result; try { string cipherString = SAFConfiguration.readConnectionStringCoreEncrypted(); string text = CryptorEngineTripleDES.Decrypt(cipherString, SAFSecurityKeys.getSecurityInfoFromWConfig(), true); result = text; } catch (Exception ex) { LOGGER.Write(LOGGER.LogCategory.ERROR, "SF.Expand.SAF.Core.DBConnectionString::ExpandSAFCore[]\r\n" + ex.Message, null); result = null; } return(result); }
/// <summary> /// </summary> /// <param name="toDecrypt"></param> /// <returns></returns> public static string Decrypt(string toDecrypt) { RSACryptoServiceProvider CSPRSA = null; try { CSPRSA = new RSACryptoServiceProvider(); CSPRSA.FromXmlString(SAFSecurityKeys.loadKeysFromFile()); byte[] toDecryptArray = Convert.FromBase64String(toDecrypt); return(Encoding.UTF8.GetString(CSPRSA.Decrypt(toDecryptArray, false))); } catch { return(null); } finally { if (CSPRSA != null) { CSPRSA.Clear(); } } }