请教大虾们,如何将下面的128位转换为16字节的byte数组?急用
33832964bf7a3b7c0f3ae3925066160e
3f66864d511f7dc43a550900bd795d02
c20db9e33a672d1a85e04f1be966a0a1
406669e6e9ddcb6ea70c7a8e0cc3ddaf

解决方案 »

  1.   

    你这些数字是来自Guid吗?
    如果是可以用Guid来表示就是了.
      

  2.   

    GUID 是一个 128 位整数(16 字节),可用于所有需要唯一标识符的计算机和网络。此标识符重复的可能性非常小。用法如下:Guid g = new Guid("33832964bf7a3b7c0f3ae3925066160e");
      

  3.   

    要表示成字节数组就简单了:
    Guid g = new Guid("33832964bf7a3b7c0f3ae3925066160e");
    byte[] bytes = g.ToByteArray();
      

  4.   

    Guid guid=Guid.NewGuid();
    byte[] bytes=guid.ToByteArray();
    Console.WriteLine(BitConverter.ToString(bytes));
      

  5.   

    Guid g = new Guid("33832964bf7a3b7c0f3ae3925066160e3f66864d511f7dc43a550900bd795d02
                      c20db9e33a672d1a85e04f1be966a0a1406669e6e9ddcb6ea70c7a8e0cc3ddaf");
    byte[] bytes = g.ToByteArray();
    这样能够是长度为16的字节数组吗?!
      

  6.   

    33832964bf7a3b7c0f3ae3925066160e
    得到:
    64-29-83-33-7A-BF-7C-3B-0F-3A-E3-92-50-66-16-0E测试的结果,估计有点问题...
    前面4个字节位置相反,第5个字节和第6个字节位置也相反...楼主,你有四排字符串,你要得到四个数组还是1个数组?
    把输出结果写出来先
      

  7.   

    Guid的参数32位的数字。
    以上方法不可用。
      

  8.   

    自已做個簡單的函數就可以了啊﹗
    private string getbytes(string stmp)
    {
    string sBytes="";
    for(int i=0;i<stmp.Length;i++)
    {
    sBytes+=IntToBytes(stmp[i]);
    }
    return sBytes;
    } private string IntToBytes(char t)
    {
    switch(t)
    {
    case '0':
    {
    return "0000";
    }
    case '1':
    {
    return "0001";
    }
    case '2':
    {
    return "0010";
    }
    case '3':
    {
    return "0011";
    }
    case '4':
    {
    return "0100";
    }
    case '5':
    {
    return "0101";
    }
    case '6':
    {
    return "0110";
    }
    case '7':
    {
    return "0111";
    }
    case '8':
    {
    return "1000";
    }
    case '9':
    {
    return "1001";
    }
    case 'a':
    {
    return "1010";
    }
    case 'b':
    {
    return "1011";
    }
    case 'c':
    {
    return "1100";
    }
    case 'd':
    {
    return "1101";
    }
    case 'e':
    {
    return "1110";
    }
    case 'f':
    {
    return "1111";
    }
    }
    }
      

  9.   

    33832964bf7a3b7c0f3ae3925066160e
    3f66864d511f7dc43a550900bd795d02
    c20db9e33a672d1a85e04f1be966a0a1
    406669e6e9ddcb6ea70c7a8e0cc3ddaf
    这几个要一个个的转,
    如果要用一个Byte数组,那么你这个数组要定义大一些,足以用来存放这几个值的字节形式.比如:byte[] bytes = new byte[32 * 4];
    byte[] bs = null;
    int startIndex = 0;
    Guid g = new Guid("33832964bf7a3b7c0f3ae3925066160e");
    bs = g.ToByteArray();
    bs.CopyTo(bytes, 0);
    startIndex =bs.Length;
    g = new Guid("3f66864d511f7dc43a550900bd795d02");
    bs = g.ToByteArray();
    bs.CopyTo(bytes, startIndex);
    startIndex += bs.Length;g = new Guid("c20db9e33a672d1a85e04f1be966a0a1");
    bs = g.ToByteArray();
    bs.CopyTo(bytes, startIndex);
    startIndex += bs.Length;g = new Guid("406669e6e9ddcb6ea70c7a8e0cc3ddaf");
    bs = g.ToByteArray();
    bs.CopyTo(bytes, startIndex);
      

  10.   

    4个字符串得到一个长度为16的数组33832964bf7a3b7c0f3ae3925066160e
    3f66864d511f7dc43a550900bd795d02
    c20db9e33a672d1a85e04f1be966a0a1
    406669e6e9ddcb6ea70c7a8e0cc3ddaf
    --------------------------------
    得到的结果是?运算的规则是?
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx共有16 * 4 个字节
    除非这个数组类型是4个字节比如int32
    楼主先说清楚你的需求
      

  11.   

    上面的是3DES的密钥,但是3DES密钥是长度为16或24的byte数组,给定的是128位(1个字节=8位)所以以上的应该能转化为长度为16的数组!
      

  12.   

    上面得到的是字符型表示的數組﹔將它轉換成byte數組就可以了,或者你在IntToBytes()函數中可以直接返回一個byte數組﹐在getbytes中將它們放在一個長數組中就可以了.
    例﹕
    private byte[] IntToBytes(char t)
    {
    switch(t)
    {
    case '0':
    {
    return new byte[]{(byte)0,(byte)0,(byte)0,(byte)0};
    }
    ....
    }
    }
      

  13.   

    byte []key = new byte[16]
    怎样将33832964bf7a3b7c0f3ae3925066160e
           3f66864d511f7dc43a550900bd795d02
           c20db9e33a672d1a85e04f1be966a0a1
           406669e6e9ddcb6ea70c7a8e0cc3ddaf)
      

  14.   

    楼主的128位16进制的数转成byte数组的长度是64字节..
    是你数错了?还是想压缩啊?
      

  15.   

    上面的是3DES的密钥,但是3DES密钥是长度为16或24的byte数组,给定的是128位(1个字节=8位)所以以上的应该能转化为长度为16的数组!
    ===========================開始的需求沒有說清楚~~
      

  16.   

    using System;
    using System.Collections.Generic;
    using System.Text;namespace ConsoleApplication1
    {
        class KEY
        {
            public byte[] bt = new byte[16];      
        }    class Program
        {
            static void Main(string[] args)
            {
                KEY[] bta = new KEY[4];
                Guid g = new Guid("33832964bf7a3b7c0f3ae3925066160e");
                bta[0] = new KEY();
                bta[0].bt = g.ToByteArray();
                bta[1] = new KEY();
                g = new Guid("3f66864d511f7dc43a550900bd795d02");
                bta[1].bt = g.ToByteArray();
                bta[2] = new KEY();
                g = new Guid("c20db9e33a672d1a85e04f1be966a0a1");
                bta[2].bt = g.ToByteArray();
                bta[3] = new KEY();
                g = new Guid("406669e6e9ddcb6ea70c7a8e0cc3ddaf");
                bta[3].bt = g.ToByteArray();            //---
            }
        }
    }
      

  17.   

    128個字節怎么能放得進長度為16的byte[]中啊﹖
    這是不可能的﹐除非你的128個字節是通過算法擴展出來的。
      

  18.   

    sqfeiyu(流星雨) 大虾,那有什么方式解决吗?!
      

  19.   

    hbicexp(飘逝如风) 要是有输出也好啊,但我没有,可以举个例子!
    比如说把:string k = "1234567890123456";
    byte []key = new byte[16];
    key = System.Text.Encoding.Default.GetBytes(k);
    现在就是 变量k 是上面的那个128位长的字符,怎样才能变为长度为16的byte数组?!
      

  20.   

    不可能直接轉換的﹐如果是3DES的密钥的話,應該有一定的轉換算法﹐所以你最好去找找它的加密算法﹐否則是沒有辦法的。
      

  21.   

    将16进制字符串转化为字节数组
    public static byte[] ConvertHexToBytes(string value)
    {
        int len = value.Length / 2;
        byte[] ret = new byte[len];
        for (int i = 0; i < len; i++)
            ret[i]=(byte)(Convert.ToInt32(value.Substring(i * 2, 2), 16));
        return ret;
    }