Beispiel #1
0
        public static string GetDatabaseBinaryPath(string eSpaceName, string entityName, string attributeName, string idValue, string fileName)
        {
            string entityDetails = SymmCryptHelper.EncryptWithAES256FixedIV(DatabaseBinaryEnvironmentPassword, entityName + "/" + attributeName + "/" + idValue, Convert.FromBase64String(PRIVATE_SALT));

            entityDetails = entityDetails.Replace("+", "-").Replace("/", "_");    /* Replace invalid URL chars */
            return("/" + eSpaceName + "/_binaryContent" + RuntimePlatformUtils.WebPageExtension + "/" + entityDetails + "/" + fileName);
        }
Beispiel #2
0
        public static string GetDatabaseBinaryRestPath(string consumerEspaceName, string entityGlobalKey, string attributeName, string idValue, int userIdLogged, byte[] binaryData)
        {
            string entityDetails = SymmCryptHelper.EncryptWithAES256FixedIV(DatabaseBinaryEnvironmentPassword, entityGlobalKey + "/" + attributeName + "/" + idValue + "/" + userIdLogged + "/" + GetBinaryContentHash(binaryData), Convert.FromBase64String(PRIVATE_SALT));

            entityDetails = entityDetails.Replace("+", "-").Replace("/", "_");    /* Replace invalid URL chars */
            return("screenservices/" + consumerEspaceName + "/_BinaryContent/" + entityDetails);
        }
Beispiel #3
0
        public static void DownloadBinary(Hashtable htDbBinaryConfig)
        {
            HttpRequest  request  = HttpContext.Current.Request;
            HttpResponse response = HttpContext.Current.Response;

            if ((request.HttpMethod.ToUpper() != "GET") && (request.HttpMethod.ToUpper() != "HEAD"))
            {
                response.AppendHeader("Allow", "GET, HEAD");
                ResponseError(response, 405, "Method Not Allowed");
                return;
            }
            string parametersString = GetParameters(request).TrimEnd('/').TrimStart('/').Replace("-", "+").Replace("_", "/");    /* Replace invalid URL chars */

            parametersString = SymmCryptHelper.DecryptWithAES256FixedIV(BinaryContentUtils.DatabaseBinaryEnvironmentPassword, parametersString, Convert.FromBase64String(PRIVATE_SALT));

            var parameters = parametersString.Split('/');

            if (parameters.Length < 3)
            {
                ResponseError(response, 400, "Bad Request");
                return;
            }

            var entity    = parameters[0].ToLower();
            var attribute = parameters[1].ToLower();
            var id        = parameters[2];

            object objt = htDbBinaryConfig[entity + "/" + attribute];

            if (objt == null)
            {
                ResponseError(response, 404, "Not Found");
                return;
            }

            DbBinaryConfig dbBinaryConfig;

            dbBinaryConfig = (DbBinaryConfig)objt;

            byte[] buffer = GetDatabaseBinaryAttribute(id, dbBinaryConfig);
            if (buffer == null)
            {
                ResponseError(response, 404, "Not Found");
            }
            else
            {
                string md5Hash = SecureHashHelper.Hash(buffer);
                response.Clear();
                response.StatusCode  = 200; //OK
                response.ContentType = RuntimePlatformUtils.GetMIMEType(buffer);
                response.AppendHeader("ETag", "\"" + md5Hash + "\"");
                response.AppendHeader("Accept-Ranges", "none");
                if (request.HttpMethod.ToUpper() == "GET")
                {
                    BinaryWrite(response, buffer);
                }
                End(response);
            }
        }
Beispiel #4
0
            public static MobileLoginInfo Read(string key, string loginInfo)
            {
                string decryptedLoginInfo = SymmCryptHelper.DecryptWithAES128(key, loginInfo);

                string[] parts = decryptedLoginInfo.Split('|');
                var      info  = new MobileLoginInfo();

                info.UserId       = Base64.IntFromBase64(parts[0]);
                info.TenantId     = Base64.IntFromBase64(parts[1]);
                info.IsPersistent = Convert.ToBoolean(Base64.IntFromBase64(parts[2]));
                return(info);
            }
Beispiel #5
0
        public static int GetBinaryContent(Dictionary <string, BinaryContentUtils.DbBinaryConfig> htDbBinaryConfig, string input, int userIdLogged, out byte[] content)
        {
            string parametersString = input.TrimEnd('/').TrimStart('/').Replace("-", "+").Replace("_", "/");

            parametersString = SymmCryptHelper.DecryptWithAES256FixedIV(BinaryContentUtils.DatabaseBinaryEnvironmentPassword, parametersString, Convert.FromBase64String(PRIVATE_SALT));
            content          = null;

            /*
             * 0 => Entity's global object key
             * 1 => Name of the binary data attribute
             * 2 => ID of the record that has the binary data
             * 3 => User ID for which the URL was generated
             * 4 => An hash of the binary data (forces the URL to change when the binary data changes)
             */
            var parameters = parametersString.Split('/');

            if (parameters.Length < 4)
            {
                return((int)HttpStatusCode.BadRequest);
            }

            var entityGlobalKey = parameters[0].ToLower();
            var attribute       = parameters[1].ToLower();
            var id     = parameters[2];
            var userId = 0;

            if (int.TryParse(parameters[3], out userId) && userId != userIdLogged)
            {
                return((int)HttpStatusCode.Unauthorized);
            }

            object objt = htDbBinaryConfig[entityGlobalKey + "/" + attribute];

            if (objt == null)
            {
                return((int)HttpStatusCode.NotFound);
            }

            DbBinaryConfig dbBinaryConfig;

            dbBinaryConfig = (DbBinaryConfig)objt;

            byte[] buffer = GetDatabaseBinaryAttribute(id, dbBinaryConfig);
            if (buffer == null)
            {
                return((int)HttpStatusCode.NotFound);
            }
            else
            {
                content = buffer;
                return((int)HttpStatusCode.OK);
            }
        }
Beispiel #6
0
            public static string Write(string key, MobileLoginInfo loginInfo)
            {
                string encoded = string.Join("|", Base64.ToBase64(loginInfo.UserId), Base64.ToBase64(loginInfo.TenantId), Base64.ToBase64(Convert.ToInt32(loginInfo.IsPersistent)));

                return(SymmCryptHelper.EncryptWithAES128(key, encoded));
            }
 public byte[] Decrypt(byte[] data, byte[] associatedData)
 {
     return(SymmCryptHelper.DecryptThenMacWithAES(Key, data, associatedData));
 }
 protected override string InnerApplyAlgorithm(string value)
 {
     return(SymmCryptHelper.EncryptWithAES128(Key, value));
 }
 protected override string InnerDecrypt(string encryptedValue)
 {
     return(SymmCryptHelper.DecryptWithAES128(Key, encryptedValue));
 }