南京海关物流监控信息化管理系统 联系客服

发布时间 : 星期一 文章南京海关物流监控信息化管理系统更新完毕开始阅读aa814768011ca300a6c390b1

(二) 验签

public static string VerifySign(string xmlContent) { if (provider.ToLower() == \) { if (verifier.ToLower() == \) { VerifySignature.VerifySignatureInterfacePortTypeClient ver = new MsgTrnsCommon.VerifySignature.VerifySignatureInterfacePortTypeClient(); return ver.xmlVerifySignature(xmlContent); } else { return UniClient.XMLVerifyMQSign(xmlContent); } } else if (provider.ToLower() == \) { if (verifier.ToLower() == \) { JsServer.SetServer(ConfigurationManager.AppSettings[\],int.Parse( ConfigurationManager.AppSettings[\])); return JsServer.gtVerifyXmlString(xmlContent); } else { UTF8Encoding ut = new UTF8Encoding(); Byte[] encodedBytes = ut.GetBytes(xmlContent); String decodedString = ut.GetString(encodedBytes); return JsClient.gtVerifyXmlString(decodedString); } } else return string.Empty; }

13

(三) 压缩

public static Stream Compress(Stream s) { s.Seek(0, SeekOrigin.Begin); MemoryStream cs = new MemoryStream(); try { DeflaterOutputStream cs1 = new DeflaterOutputStream(s, new Deflater(Deflater.BEST_COMPRESSION)); StreamCopy(cs, cs1, streamCopyBufferSize); } catch (Exception ex) { Logging.LogManager.GetLogger().Error(\压缩程序出错\, ex); throw ex; } cs.Seek(0, SeekOrigin.Begin); return cs; }

(四) 解压缩

public static Stream Decompress(Stream s) { InflaterInputStream inflaterInputStream = null; try { s.Seek(0, SeekOrigin.Begin); inflaterInputStream = new InflaterInputStream(s); } catch (Exception ex) { Logging.LogManager.GetLogger().Error(\解压缩出错\, ex); throw (new Exception(\出错函数\ + \ + ex.Message)); } return inflaterInputStream; }

(五) 字节数组与Base64的转换:

14

static void Main(string[] args) { string factString = \中华人民共和国\; byte[] myByte; string Base64Str; //先把字符串按照utf-8的编码转换成byte[] Encoding myEncoding = Encoding.GetEncoding(\); //myByte中获得这样的字节数组:228,184,173,229,141,142,228,186,186,230,176,145,229,133,177,229,146,140,229,155,189 myByte = myEncoding.GetBytes(factString); //把byte[]转成base64编码,这个例子形成的base64编码的unicode等价字符串为:\ Base64Str = Convert.ToBase64String(myByte); //再从base64编码转成byte[],又恢复为字节数组:228,184,173,229,141,142,228,186,186,230,176,145,229,133,177,229,146,140,229,155,189 myByte = Convert.FromBase64String(Base64Str); //用同一个Encoding对象把byte[]转成字符串:\中华人民共和国\ factString = myEncoding.GetString(myByte); Console.WriteLine(factString); }

注:以上程序片断不作为报文传输软件开发依据,仅供开发时参考。

15