protected bool CheckAccessCore(OperationContext operationContext, string username, string token) { try { string ip = ""; //AspNetCache cache = Utility.Cache.AspNetCache; MessageProperties prop = operationContext.IncomingMessageProperties; var endpoint = prop[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; if (endpoint != null) { ip = endpoint.Address; } var message = operationContext.RequestContext.RequestMessage; string action = operationContext.IncomingMessageHeaders.Action; Uri actionUri = new Uri(action); var methodName = actionUri.Segments.Last(); if (!methodName.ToLower().Equals("servielogin")) { //string token = ""; var encoding = Encoding.UTF8; var encryptedKey = TripleDESProvider.Encrypt(token); var keyByte = encoding.GetBytes(encryptedKey); var hmacsha512 = new HMACSHA512(keyByte); var hashmessage = hmacsha512.ComputeHash(keyByte); var enckey = Convert.ToBase64String(hashmessage); var login = WcfAutenticationProvider.Get(); if (login.TockenKey == enckey && login.UserName == username) { //TWO Hours if ((DateTime.Now - login.LastSet).Minutes > 120) { return(false); } return(true); //TODO: add CheckAccess //return CheckAccess(operationContext, "", actionUri, ip, ""); } else { return(false); } } else { } return(true); } catch (Exception) { return(false); } }
/// <summary> /// Does the actual saving. /// </summary> public override void Close() { // save the file to the filestream FileStream fs = new FileStream(Filename, FileMode.Create); if (Encryption == EncryptionType.AES) { fs.Write(AESProvider.Encrypt(Text.ToArray()), 0, Text.Count); } if (Encryption == EncryptionType.ASCII) { fs.Write(Utilities.StringToByte(ASCIIProvider.Encrypt(Utilities.ByteToString(Text.ToArray()))), 0, Text.Count); } if (Encryption == EncryptionType.DES) { fs.Write(DESProvider.Encrypt(Text.ToArray()), 0, Text.Count); } if (Encryption == EncryptionType.L1F3) { fs.Write(L1F3Provider.Encrypt(Utilities.ByteToString(Text.ToArray())), 0, Text.Count); } if (Encryption == EncryptionType.RC2) { fs.Write(RC2Provider.Encrypt(Text.ToArray()), 0, Text.Count); } if (Encryption == EncryptionType.Rijndael) { fs.Write(RijndaelProvider.Encrypt(Text.ToArray()), 0, Text.Count); } if (Encryption == EncryptionType.RSA) { fs.Write(RSAProvider.Encrypt(Text.ToArray()), 0, Text.Count); } if (Encryption == EncryptionType.TripleDES) { fs.Write(TripleDESProvider.Encrypt(Text.ToArray()), 0, Text.Count); } if (Encryption == EncryptionType.Xor) { fs.Write(Utilities.StringToByte(XorProvider.Encrypt(Utilities.ByteToString(Text.ToArray()))), 0, Text.Count); } fs.Close(); base.Close(); }
public static LuaValue Encrypt(LuaValue[] args) { string encType = (args[0] as LuaString).Text.ToLower(); string _in = args[1].ToString(); if (encType == "aes") { return(new LuaString(AESProvider.Encrypt(_in))); } else if (encType == "ascii") { // encrypt with first byte of key return(new LuaString(ASCIIProvider.Encrypt(_in))); } if (encType == "des") { return(new LuaString(DESProvider.Encrypt(_in))); } if (encType == "rc2") { return(new LuaString(RC2Provider.Encrypt(_in))); } if (encType == "rijndael") { return(new LuaString(RijndaelProvider.Encrypt(_in))); } if (encType == "rsa") { return(new LuaString(RSAProvider.Encrypt(_in))); } if (encType == "tripledes") { return(new LuaString(TripleDESProvider.Encrypt(_in))); } if (encType == "xor") { return(new LuaString(XorProvider.Encrypt(_in))); } throw new Exception("Unsuported encryption '" + encType + "'!"); }