Ejemplo n.º 1
0
        public static void GetPurposeAndClearData(ReadObject objData, out Purpose objPurpose, out byte[] byteClearData)
        {
            switch (enumPurpose)
            {
            case EnumPurpose.OWINCOOKIE:
                Dictionary <string, Purpose> dictPurposeMap = new Dictionary <string, Purpose>(StringComparer.Ordinal)
                {
                    { "owin.cookie", Purpose.User_MachineKey_Protect.AppendSpecificPurposes(
                          new [] {
                            "Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware",
                            "ApplicationCookie",
                            "v1"
                        }
                          ) }
                };
                dictPurposeMap.TryGetValue("owin.cookie", out objPurpose);
                byteClearData = DataWriter.Compress(StringToHexByteArray(objData.AspNetAppCookie));
                break;

            case EnumPurpose.ASPXAUTH:
                objPurpose    = Purpose.FormsAuthentication_Ticket;
                byteClearData = FormAuthenticationHelper.ConvertToBytes(objData.objFormAuthCookie);
                break;

            case EnumPurpose.WEBRESOURCE:
                objPurpose    = Purpose.AssemblyResourceLoader_WebResourceUrl;
                byteClearData = Encoding.ASCII.GetBytes(objData.WebResourceData);
                break;

            case EnumPurpose.SCRIPTRESOURCE:
                objPurpose    = Purpose.ScriptResourceHandler_ScriptResourceUrl;
                byteClearData = Encoding.ASCII.GetBytes(objData.ScriptResourceData);
                break;

            case EnumPurpose.VIEWSTATE:
                byteClearData = null;
                objPurpose    = null;
                break;

            case EnumPurpose.UNKNOWN:
                byteClearData = null;
                objPurpose    = null;
                break;

            default:
                byteClearData = null;
                objPurpose    = null;
                break;
            }
        }
Ejemplo n.º 2
0
        public static string EncryptData(string strDecryptDataFilePath)
        {
            ReadObject objData = new ReadObject(strDecryptDataFilePath);
            AspNetCryptoServiceProvider obj = new AspNetCryptoServiceProvider(
                objData.ValidationKey,
                objData.ValidationAlgo, objData.DecryptionKey, objData.DecryptionAlgo);

            obj.SetEncryptionIV(objData.EncryptionIV);
            DefinePurpose.SetPurposeString(objData.Purpose);

            Purpose objPurpose = null;

            byte[] byteClearData = null;
            DefinePurpose.GetPurposeAndClearData(objData, out objPurpose, out byteClearData);
            ICryptoService cryptoService = obj.GetCryptoService(objPurpose);

            return(PrintData(cryptoService.Protect(byteClearData)));
        }