There is a 3rd party code, which returns me the string "Nmimtech1" in form of a byte[] array.

    object password1 = pProps.GetProperty("PASSWORD"); 

(Its third party ESRI library code, so do not bother) Now i convert it to byte[]

    byte[] pswrdbyte = password1 as byte[]

The content of this byte array are

        [0] 2   byte
    [1] 0   byte
    [2] 0   byte
    [3] 0   byte
    [4] 20  byte
    [5] 0   byte
    [6] 0   byte
    [7] 0   byte
    [8] 200 byte
    [9] 115 byte
    [10]    39  byte
    [11]    180 byte
    [12]    150 byte
    [13]    100 byte
    [14]    74  byte
    [15]    44  byte
    [16]    7   byte
    [17]    215 byte
    [18]    137 byte
    [19]    50  byte
    [20]    212 byte
    [21]    138 byte
    [22]    56  byte
    [23]    241 byte
    [24]    134 byte
    [25]    51  byte
    [26]    75  byte
    [27]    0   byte

Now i have tried each and every way to convert it back to "Nmimtech1

    string str = System.Text.Encoding.ASCII.GetString(pswrdbyte);

returns "\0\0\0\0\0\0?s'??dJ,\a??2??8??3K\0"

    string str1 = System.Text.Encoding.Unicode.GetString(pswrdbyte);

returns "\0\0珈됧撖ⱊ휇㊉諔㎆K"

    string str2 = System.Text.Encoding.UTF8.GetString(pswrdbyte);

returns "\0\0\0\0\0\0�s'��dJ,\a׉2Ԋ8�3K\0"

    string str3 =  System.Text.Encoding.UTF32.GetString(pswrdbyte);

returns "�����"

    string str4 = System.Text.Encoding.UTF7.GetString(pswrdbyte);

returns "\0\0\0\0\0\0Ès'´dJ,\a×2Ô8ñ3K\0"

    string str5 = System.Text.Encoding.BigEndianUnicode.GetString(pswrdbyte);

returns "Ȁ\0᐀\0졳➴除䨬ߗ褲풊㣱蘳䬀"

    string str6 = pswrdbyte.ToString();

returns "System.Byte[]" (weird)

    string s  = BitConverter.ToString(pswrdbyte);

returns "02-00-00-00-14-00-00-00-C8-73-27-B4-96-64-4A-2C-07-D7-89-32-D4-8A-38-F1-86-33-4B-00". Now this makes a little sense, but can you tell me how to convert this hex string back to "Nmimtech1" programmatically?

有帮助吗?

解决方案 2

Sorry guys, The password returned from Thirdparty code is encrypted, and i figured out we cant decrypt it. Rather, to store it locally, i will need to store the encrypted form. Thanks

其他提示

if your 3rd party code returns your string in form of a byte array, why you convert it to a byte array again?

Now i convert it to byte[]: byte[] pswrdbyte = password1 as byte[]

?

        String password1 = "Nmimtech1";
        System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

        byte[] pswrdbyte = enc.GetBytes(password1);

enter image description here

        string password2 = enc.GetString(pswrdbyte);

password2 contains "Nmimtech1" again.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top