private byte[] GetLegalKey(string Key)
{
string sTemp;
if (mobjCryptoService.LegalKeySizes.Length > 0)
{
int lessSize = 0, moreSize = mobjCryptoService.LegalKeySizes[0].MinSize;
// key sizes are in bits
while (Key.Length * 8 > moreSize)
{
lessSize = moreSize;
moreSize += mobjCryptoService.LegalKeySizes[0].SkipSize;
}
sTemp = Key.PadRight(moreSize / 8, ' ');
}
else
sTemp = Key; // convert the secret key to byte array
return ASCIIEncoding.ASCII.GetBytes(sTemp);
} public string jiami(string Source, string Key)
{
byte[] bytIn = System.Text.ASCIIEncoding.ASCII.GetBytes(Source);
// create a MemoryStream so that the process can be done without I/O files
System.IO.MemoryStream ms = new System.IO.MemoryStream(); byte[] bytKey = GetLegalKey(Key); // set the private key
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey; // create an Encryptor from the Provider Service instance
ICryptoTransform encrypto = mobjCryptoService.CreateEncryptor(); // create Crypto Stream that transforms a stream using the encryption
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Write); // write out encrypted content into MemoryStream
cs.Write(bytIn, 0, bytIn.Length);
cs.FlushFinalBlock();
            
// get the output and trim the '\0' bytes
byte[] bytOut = ms.GetBuffer();
int i = 0;
for (i = 0; i < bytOut.Length; i++)
if (bytOut[i] == 0)
break;
                    
// convert into Base64 so that the result can be used in xml
return System.Convert.ToBase64String(bytOut, 0, i);
} public string jiemi(string Source, string Key)
{
// convert from Base64 to binary
byte[] bytIn = System.Convert.FromBase64String(Source);
// create a MemoryStream with the input
System.IO.MemoryStream ms = new System.IO.MemoryStream(bytIn, 0, bytIn.Length); byte[] bytKey = GetLegalKey(Key); // set the private key
mobjCryptoService.Key = bytKey;
mobjCryptoService.IV = bytKey; // create a Decryptor from the Provider Service instance
ICryptoTransform encrypto = mobjCryptoService.CreateDecryptor();
 
// create Crypto Stream that transforms a stream using the decryption
CryptoStream cs = new CryptoStream(ms, encrypto, CryptoStreamMode.Read); // read out the result from the Crypto Stream
System.IO.StreamReader sr = new System.IO.StreamReader( cs );
return sr.ReadToEnd();
}
看看这个算法。可能对你有帮助。

解决方案 »

  1.   

    非常感谢我是看不太懂asp的算法,呵呵,虽然还没有解决我的问题,但还感谢你的热心,结帖子时给你加20分!
      

  2.   

    using System;
    using Microsoft.VisualBasic;
    using System.Runtime.CompilerServices;
    using Microsoft.VisualBasic.CompilerServices;namespace ClassLibrary1
    {
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public class Class1
    {
    public Class1()
    {}
    public object bu_Bytes2Int(object[] aBytes, object index)
    {
    object obj2 = ObjectType.AddObj(ObjectType.AddObj(ObjectType.AddObj(aBytes[IntegerType.FromObject(index)], ObjectType.MulObj(aBytes[IntegerType.FromObject(ObjectType.AddObj(index, 1))], 0x100)), ObjectType.MulObj(aBytes[IntegerType.FromObject(ObjectType.AddObj(index, 2))], 0x10000)), ObjectType.MulObj(aBytes[IntegerType.FromObject(ObjectType.AddObj(index, 3))], 0x1000000));
    return RuntimeHelpers.GetObjectValue(obj2);
    }
    public object bu_String2Bytes(object str, object[] aBytes)
    {
    object obj2=new object();
    object obj4=new object();
    object obj3 = Strings.Len(RuntimeHelpers.GetObjectValue(str));
    if (FlowControl.ForLoopInitObj(obj2, 0, ObjectType.SubObj(obj3, 1), 1, ref obj4, ref obj2))
    {
    do
    {
    aBytes[IntegerType.FromObject(obj2)] = Strings.Asc(Strings.Mid(StringType.FromObject(str), IntegerType.FromObject(ObjectType.AddObj(obj2, 1)), 1));
    }
    while (FlowControl.ForNextCheckObj(obj2, obj4, ref obj2));
    }
    return RuntimeHelpers.GetObjectValue(obj3);
    }
     
    public object encrypt(object password)
    {
    object obj3=new object();
    object obj7=new object();
    object obj10=new object();
    object obj13=new object();
    object[] objArray2 = new object[0x11];
    object[] objArray1 = new object[0x11];
    this.bu_String2Bytes(RuntimeHelpers.GetObjectValue(password), objArray2);
    this.bu_String2Bytes(RuntimeHelpers.GetObjectValue(password), objArray1);
    object obj4 = ObjectType.AddObj(ObjectType.MulObj(this.bu_Bytes2Int(objArray2, 0), 0x3407f), 0x269735);
    obj4 = ObjectType.SubObj(obj4, ObjectType.MulObj(Conversion.Fix(ObjectType.DivObj(obj4, 0x100000000)), 0x100000000));
    object obj6 = ObjectType.AddObj(ObjectType.MulObj(this.bu_Bytes2Int(objArray2, 4), 0x340ff), 0x269741);
    obj6 = ObjectType.SubObj(obj6, ObjectType.MulObj(Conversion.Fix(ObjectType.DivObj(obj6, 0x100000000)), 0x100000000));
    object obj5 = ObjectType.AddObj(ObjectType.MulObj(this.bu_Bytes2Int(objArray2, 8), 0x340d3), 0x269935);
    obj5 = ObjectType.SubObj(obj5, ObjectType.MulObj(Conversion.Fix(ObjectType.DivObj(obj5, 0x100000000)), 0x100000000));
    object obj2 = ObjectType.AddObj(ObjectType.MulObj(this.bu_Bytes2Int(objArray2, 12), 0x3433d), 0x269acd);
    obj2 = ObjectType.SubObj(obj2, ObjectType.MulObj(Conversion.Fix(ObjectType.DivObj(obj2, 0x100000000)), 0x100000000));
    this.MyuwSplit(ref obj4, RuntimeHelpers.GetObjectValue(objArray2[0]), RuntimeHelpers.GetObjectValue(objArray2[1]), RuntimeHelpers.GetObjectValue(objArray2[2]), RuntimeHelpers.GetObjectValue(objArray2[3]));
    this.MyuwSplit(ref obj6, RuntimeHelpers.GetObjectValue(objArray2[4]), RuntimeHelpers.GetObjectValue(objArray2[5]), RuntimeHelpers.GetObjectValue(objArray2[6]), RuntimeHelpers.GetObjectValue(objArray2[7]));
    this.MyuwSplit(ref obj5, RuntimeHelpers.GetObjectValue(objArray2[8]), RuntimeHelpers.GetObjectValue(objArray2[9]), RuntimeHelpers.GetObjectValue(objArray2[10]), RuntimeHelpers.GetObjectValue(objArray2[11]));
    this.MyuwSplit(ref obj2, RuntimeHelpers.GetObjectValue(objArray2[12]), RuntimeHelpers.GetObjectValue(objArray2[13]), RuntimeHelpers.GetObjectValue(objArray2[14]), RuntimeHelpers.GetObjectValue(objArray2[15]));
    objArray1[0] = ObjectType.BitXorObj(objArray1[0], objArray2[0]);
    if (FlowControl.ForLoopInitObj(obj3, 1, 15, 1, ref obj13, ref obj3))
    {
    do
    {
    objArray1[IntegerType.FromObject(obj3)] = ObjectType.BitXorObj(ObjectType.BitXorObj(objArray1[IntegerType.FromObject(obj3)], objArray1[IntegerType.FromObject(ObjectType.SubObj(obj3, 1))]), objArray2[IntegerType.FromObject(ObjectType.BitAndObj(obj3, 15))]);
    }
    while (FlowControl.ForNextCheckObj(obj3, obj13, ref obj3));
    }
    if (FlowControl.ForLoopInitObj(obj3, 0, 15, 1, ref obj10, ref obj3))
    {
    do
    {
    if (ObjectType.ObjTst(objArray1[IntegerType.FromObject(obj3)], 0, false) == 0)
    {
    objArray1[IntegerType.FromObject(obj3)] = 0x66;
    }
    }
    while (FlowControl.ForNextCheckObj(obj3, obj10, ref obj3));
    }
    object obj1 = "0x";
    if (FlowControl.ForLoopInitObj(obj3, 0, 15, 1, ref obj7, ref obj3))
    {
    do
    {
    if (ObjectType.ObjTst(objArray1[IntegerType.FromObject(obj3)], 0x10, false) < 0)
    {
    obj1 = ObjectType.StrCatObj(ObjectType.StrCatObj(obj1, "0"), Conversion.Hex(RuntimeHelpers.GetObjectValue(objArray1[IntegerType.FromObject(obj3)])));
    }
    else
    {
    obj1 = ObjectType.StrCatObj(obj1, Conversion.Hex(RuntimeHelpers.GetObjectValue(objArray1[IntegerType.FromObject(obj3)])));
    }
    }
    while (FlowControl.ForNextCheckObj(obj3, obj7, ref obj3));
    }
    return obj1;
    }
    public void MyuwSplit(ref object w, object a, object b, object C, object d)
    {
    d = RuntimeHelpers.GetObjectValue(Conversion.Fix(ObjectType.DivObj(w, 0x1000000)));
    C = RuntimeHelpers.GetObjectValue(Conversion.Fix(ObjectType.DivObj(ObjectType.SubObj(w, ObjectType.MulObj(d, 0x1000000)), 0x10000)));
    b = RuntimeHelpers.GetObjectValue(Conversion.Fix(ObjectType.DivObj(ObjectType.SubObj(ObjectType.SubObj(w, ObjectType.MulObj(d, 0x1000000)), ObjectType.MulObj(C, 0x10000)), 0x100)));
    a = RuntimeHelpers.GetObjectValue(Conversion.Fix(ObjectType.SubObj(ObjectType.SubObj(ObjectType.SubObj(w, ObjectType.MulObj(d, 0x1000000)), ObjectType.MulObj(C, 0x10000)), ObjectType.MulObj(b, 0x100))));
    } }
    }
      

  3.   

    是VB到C#的转换代码,没有测试,能够编译!
    不过还是用到了Microsoft.VisualBasic的引用,请在引用处加上
    Microsoft VisualBasic .Net Runtime
      

  4.   

    转换是不正确的,编译虽然没问题,但结果不对
    其他的代码写成c#没有问题,我只想知道d = Fix(w / &H1000000),如果取得&H1000000内存地址?
    感谢您的回复!