OpenSSL

在计算机网络上,OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。这个包广泛被应用在互联网的网页服务器上。

安装

1、准备编译环境

yum install gcc

2、下载OpenSSL源码

wget https://github.com/openssl/openssl/archive/OpenSSL_1_1_1c.tar.gz

3、解压

tar -xzf OpenSSL_1_1_1c.tar.gz

4、配置

cd openssl-OpenSSL_1_1_1c
./config --prefix=/usr

5、编译&&安装

make && make install
ldconfig

7、查看安装版本

openssl version

OpenSSL 1.1.1c 28 May 2019

解决微软MVC请求响应的JSON的日期格式问题。需要结合StringBuilder

JavaScriptSerializer = {};
JavaScriptSerializer._charsToEscapeRegExs = [];
JavaScriptSerializer._charsToEscape = [];
JavaScriptSerializer._dateRegEx = new RegExp('(^|[^\\\\])\\"\\\\/Date\\((-?[0-9]+)(?:[a-zA-Z]|(?:\\+|-)[0-9]{4})?\\)\\\\/\\"', 'g');
JavaScriptSerializer._escapeChars = {};
JavaScriptSerializer._escapeRegEx = new RegExp('["\\\\\\x00-\\x1F]', 'i');
JavaScriptSerializer._escapeRegExGlobal = new RegExp('["\\\\\\x00-\\x1F]', 'g');
JavaScriptSerializer._jsonRegEx = new RegExp('[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \\n\\r\\t]', 'g');
JavaScriptSerializer._jsonStringRegEx = new RegExp('"(\\\\.|[^"\\\\])*"', 'g');
JavaScriptSerializer._init = function () {
    var replaceChars = ['\\u0000', '\\u0001', '\\u0002', '\\u0003', '\\u0004', '\\u0005', '\\u0006', '\\u0007',
                        '\\b', '\\t', '\\n', '\\u000b', '\\f', '\\r', '\\u000e', '\\u000f', '\\u0010', '\\u0011',
                        '\\u0012', '\\u0013', '\\u0014', '\\u0015', '\\u0016', '\\u0017', '\\u0018', '\\u0019',
                        '\\u001a', '\\u001b', '\\u001c', '\\u001d', '\\u001e', '\\u001f'];
    JavaScriptSerializer._charsToEscape[0] = '\\';
    JavaScriptSerializer._charsToEscapeRegExs['\\'] = new RegExp('\\\\', 'g');
    JavaScriptSerializer._escapeChars['\\'] = '\\\\';
    JavaScriptSerializer._charsToEscape[1] = '"';
    JavaScriptSerializer._charsToEscapeRegExs['"'] = new RegExp('"', 'g');
    JavaScriptSerializer._escapeChars['"'] = '\\"';
    for (var i = 0; i < 32; i++) {
        var c = String.fromCharCode(i);
        JavaScriptSerializer._charsToEscape[i + 2] = c;
        JavaScriptSerializer._charsToEscapeRegExs[c] = new RegExp(c, 'g');
        JavaScriptSerializer._escapeChars[c] = replaceChars[i];
    }
}
JavaScriptSerializer.serialize = function (object) {
    var stringBuilder = new StringBuilder();
    var booleanWithBuilder = function (bool, builder) {
        if (typeof bool !== 'undefined') {
            builder.append(bool);
        } else {
            builder.append('false');
        }
    }
    var numberWithBuilder = function (number, builder) {
        if (typeof number !== 'undefined' && number.toString() !== 'NaN') {
            builder.append(number);
        } else {
            builder.append('null');
        }
    }
    var stringWithBuilder = function (string, builder) {
        builder.append('"');
        if (JavaScriptSerializer._escapeRegEx.test(string)) {
            if (JavaScriptSerializer._charsToEscape.length === 0) {
                JavaScriptSerializer._init();
            }
            if (string.length < 128) {
                string = string.replace(JavaScriptSerializer._escapeRegExGlobal,
                function (x) { return JavaScriptSerializer._escapeChars[x]; });
            }
            else {
                for (var i = 0; i < 34; i++) {
                    var c = JavaScriptSerializer._charsToEscape[i];
                    if (string.indexOf(c) !== -1) {
                        if ($.browser.opera || $.browser.mozilla) {
                            string = string.split(c).join(JavaScriptSerializer._escapeChars[c]);
                        }
                        else {
                            string = string.replace(JavaScriptSerializer._charsToEscapeRegExs[c],
                            JavaScriptSerializer._escapeChars[c]);
                        }
                    }
                }
            }
        }
        builder.append(string);
        builder.append('"');
    }
    var dateWithBuilder = function (date, builder) {
        if (date && date.toString() !== 'NaN') {
            builder.append('"\\/Date(');
            var timeOffset = date.getTimezoneOffset() * 60 * 1000;
            if (timeOffset != 0) {
                var time = date.getTime() - timeOffset;
                builder.append(time);
            }
            else {
                builder.append(date.getTime());
            }
            builder.append(')\\/"');
        } else {
            builder.append('null');
        }
    }
    var plainObjectWithBuilder = function (plainObject, builder) {
        builder.append('{');
        var row = 0;
        for (var item in plainObject) {
            if (row++ > 0) {
                builder.append(',');
            }
            stringWithBuilder(item, builder);
            builder.append(':');
            withBuilder(plainObject[item], builder);
        }
        builder.append('}');
    }
    var arrayWithBuilder = function (array, builder) {
        if (array) {
            builder.append('[');
            if (array.length > 0) {
                $.each(array, function (i, item) {
                    if (i > 0) {
                        builder.append(',');
                    }
                    withBuilder(item, builder);
                });
            }
            builder.append(']');
        } else {
            builder.append('null');
        }
    }
    var withBuilder = function (object, builder) {
        builder = builder || new StringBuilder();
        var type = $.type(object);
        switch (type) {
            case 'object':
                if (object) {
                    if (jQuery.isPlainObject(object)) {
                        plainObjectWithBuilder(object, builder);
                    } else {
                        builder.append('null');
                    }
                } else {
                    builder.append('null');
                }
                break;
            case 'array':
                arrayWithBuilder(object, builder);
                break;
            case 'number':
                numberWithBuilder(object, builder);
                break;
            case 'string':
                stringWithBuilder(object, builder);
                break;
            case 'date':
                dateWithBuilder(object, builder);
                break;
            case 'boolean':
                booleanWithBuilder(object, builder);
                break;
            default:
                builder.append('null');
                break;
        }
    }

    withBuilder(object, stringBuilder);

    return stringBuilder.toString();
}
JavaScriptSerializer.deserialize = function (data, secure) {
    if (data == null || typeof data !== "string" || data.length === 0) {
        return null;
    }
    var exp = data.replace(JavaScriptSerializer._dateRegEx, "$1new Date($2)");
    try {
        if (secure && JavaScriptSerializer._jsonRegEx.test(exp.replace(JavaScriptSerializer._jsonStringRegEx, ''))) {
            throw null;
        }
    } catch (e) {
        throw 'Cannot deserialize. The data does not correspond to valid JSON.';
    }
    return eval('(' + exp + ')');
}

StringBuilder = function (initialText) {
    this._array = (typeof (initialText) !== 'undefined' && initialText !== null && initialText !== '') ? [initialText] : [];
    this.append = function (text) {
        this._array[this._array.length] = text;
    }
    this.appendLine = function (text) {
        this._array[this._array.length] = ((typeof (text) === 'undefined') || (text === null) || (text === '')) ? '\r\n' : text + '\r\n';
    }
    this.clear = function (text) {
        this._array = [];
    }
    this.isEmpty = function () {
        return (this._array.length == 0 ? true : false);
    }
    this.toString = function (separator) {
        separator = separator || ''
        var array = this._array;
        if (separator !== '') {
            for (var i = 0; i < array.length; ) {
                if ((typeof (array[i]) === 'undefined') || (array[i] === '') || (array[i] === null)) {
                    array.splice(i, 1);
                }
                else {
                    i++;
                }
            }
        }
        return array.join(separator);
    }
    this.indexOf = function (searchvalue) {
        return this._array.indexOf(searchvalue);
    }
    this.contains = function (text) {
        return this._array.contains(text);
    }
}

public sealed class AcrobatUtil
{
	public string ConvertToExecl(string inputFileName, string outputFileName)
	{
		//判断文件是否存在
		if (!File.Exists(inputFileName))
		{
			return "File Is Missing";
		}
		try
		{
			//判断是否已经安装Acrobat
			string acrobatPath = GetAppPath();
			if (acrobatPath == null)
			{
				return "Adobe Acrobat not installed.";
			}

			var aVDoc = new AcroAVDoc();
			aVDoc.Open(inputFileName, "");
			CAcroPDDoc PDDoc = (CAcroPDDoc)aVDoc.GetPDDoc();
			object jsObj = PDDoc.GetJSObject();
			var jsObjType = jsObj.GetType();
			//另存为
			jsObjType.InvokeMember(
							"saveAs",
							BindingFlags.InvokeMethod |
							BindingFlags.Public |
							BindingFlags.Instance,
							null, jsObj, new object[] { outputFileName, "com.adobe.acrobat.xlsx" });
/*
另存为更多格式
html htm      com.adobe.acrobat.html
jpeg jpg      com.adobe.acrobat.jpeg
docx          com.adobe.acrobat.docx
doc           com.adobe.acrobat.doc
png           com.adobe.acrobat.png
ps            com.adobe.acrobat.ps
rft           com.adobe.acrobat.rft
xlsx          com.adobe.acrobat.xlsx
xls           com.adobe.acrobat.spreadsheet
txt           com.adobe.acrobat.accesstext
tiff tif      com.adobe.acrobat.tiff
xml           com.adobe.acrobat.xml-1-00
*/
			//关闭文档
			aVDoc.Close(1);
		}
		catch (Exception ex)
		{
			return "Error:" + ex.Message;
		}
		return null;
	}
	
	//获取Acrobat安装路径
	private string GetAppPath()
	{
		string acrobatPath = null;
		using (RegistryKey acrobatRegistryKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Adobe\Adobe Acrobat"))
		{
			if (acrobatRegistryKey == null)
			{
				return acrobatPath;
			}
			string acrobatVersion = acrobatRegistryKey.GetValue("TrackName").ToString();
			using (RegistryKey acrobatInstallPathRegistryKey = acrobatRegistryKey.OpenSubKey(acrobatVersion + @"\InstallPath"))
			{
				if (acrobatInstallPathRegistryKey == null)
				{
					return acrobatPath;
				}
				acrobatPath = acrobatInstallPathRegistryKey.GetValue("").ToString() + @"\Acrobat.exe";
			}
		}
		return acrobatPath;
	}
}