public string EncryptString(string inStr, string inKey, bool?md5 = null) { string outStr = string.Empty; var hasher = new ROHasher(md5 != null ? md5.Value : _md5); var encryptor = new ROPwdCrypto(md5 != null ? md5.Value : _md5); try { outStr = Convert.ToBase64String( encryptor.Encrypt( hasher.ComputeHash(UTF8Encoding.UTF8.GetBytes(inKey)), UTF8Encoding.UTF8.GetBytes(inStr)) ); } catch (Exception ex) { outStr = null; if (ex == null) { throw; } } hasher = null; encryptor = null; return(outStr); }
protected string DecryptString(string inStr, string inKey, bool?md5 = null) { if (string.IsNullOrEmpty(inStr)) { return(null); } string outStr = ""; var hasher = new ROHasher(md5 != null ? md5.Value : _md5); var encryptor = new ROPwdCrypto(md5 != null ? md5.Value : _md5); try { outStr = UTF8Encoding.UTF8.GetString( encryptor.Decrypt( hasher.ComputeHash(UTF8Encoding.UTF8.GetBytes(inKey)), Convert.FromBase64String(inStr)) ); } catch { outStr = null; } hasher = null; encryptor = null; return(outStr); }