当前位置:编程学习 > C#/ASP.NET >>

关于using System.Web.Configuration怎么也想不通的问题?【100分】求解




using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Web.Configuration;
using System.Web.Security;


/// <summary>
/// HanShu 的摘要说明
/// </summary>
public class jami
{
    public jami() { }


    public static string DecryptDBStr(string Text, string sKey)   //   【验证=8】
    {

      return MachineKeySection.ByteArrayToHexString(algorithm.ComputeHash(Encoding.UTF8.GetBytes(password)), 0);

    }


}



=============================================================
郁闷死了,哪位高手能给点拨一下!
using System.Web.Configuration;已经有了,怎么就没有ByteArrayToHexString





String 类 Configuration using using System --------------------编程问答-------------------- http://msdn.microsoft.com/en-us/library/microsoft.biztalk.snapin.framework.querybuilder.streamparser.bytearraytohexstring(v=bts.20).aspx

Namespace: Microsoft.BizTalk.SnapIn.Framework.QueryBuilder
Assembly: Microsoft.BizTalk.SnapIn.Framework (in microsoft.biztalk.snapin.framework.dll) --------------------编程问答-------------------- 程序集版本?
net 4.0 ? --------------------编程问答-------------------- internal static unsafe string ByteArrayToHexString(byte[] buf, int iLen)
internal的,你在外面当然看不到了 --------------------编程问答-------------------- 要么是程序集版本不对应
要么是此方法没有public
--------------------编程问答-------------------- 就是不行呀,谁有心可以在自己的环境试试这段代码或查一下自己的using System.Web.Configuration;是否有ByteArrayToHexString
解决不了,如果真正解决了,不行再送100分。 --------------------编程问答--------------------
System.Web.Configuration.MachineKeySection 中已经提供了一个名为 ByteArrayToHexString 方法,但是该方法是NonPublic 的,我们不能直接调用。这里我们通过反射来调用 MachineKeySection 中的 ByteArrayToHexString 方法。

 /// <summary>
        /// 字节数组转换为16进制表示的字符串
        /// </summary>
        public static string ByteArrayToHexString(byte[] buf)
        {
            int iLen = 0;

            // 通过反射获取 MachineKeySection 中的 ByteArrayToHexString 方法,该方法用于将字节数组转换为16进制表示的字符串。
            Type type = typeof(System.Web.Configuration.MachineKeySection);
            MethodInfo byteArrayToHexString = type.GetMethod("ByteArrayToHexString", BindingFlags.Static | BindingFlags.NonPublic);

            // 字节数组转换为16进制表示的字符串
            return (string)byteArrayToHexString.Invoke(null, new object[] { buf, iLen });
        }
--------------------编程问答--------------------
引用 6 楼 Return_false 的回复:
System.Web.Configuration.MachineKeySection 中已经提供了一个名为 ByteArrayToHexString 方法,但是该方法是NonPublic 的,我们不能直接调用。这里我们通过反射来调用 MachineKeySection 中的 ByteArrayToHexString 方法。

 /// <summary>
        /// 字节数组转换为16进制表示的字符串
        /// </summary>
        public static string ByteArrayToHexString(byte[] buf)
        {
            int iLen = 0;

            // 通过反射获取 MachineKeySection 中的 ByteArrayToHexString 方法,该方法用于将字节数组转换为16进制表示的字符串。
            Type type = typeof(System.Web.Configuration.MachineKeySection);
            MethodInfo byteArrayToHexString = type.GetMethod("ByteArrayToHexString", BindingFlags.Static | BindingFlags.NonPublic);

            // 字节数组转换为16进制表示的字符串
            return (string)byteArrayToHexString.Invoke(null, new object[] { buf, iLen });
        }

+1
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,