Parsing Binary(64) SQL Server Data To Plain Text In C# [duplicate]












-1
















This question already has an answer here:




  • How do I decode a base64 encoded string?

    2 answers




I have a SQL Server database with a binary(64) column housing a password. I am using a C# ASP.NET API to query the data and return the data as a string back to my C# code.



In SQL Server the password is



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


In my C# the password as a string is



UHVycGxlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==


And in plain text the password is: Purple



My question at hand is how can I use C# to "parse" the returned string and convert it to readable format?



I tried the below syntax, but I get an error of... What would be the proper way to "parse" the hashed password into plain text?




Could not find any recognizable digits




public class SQLData
{
public string pass { get; set; }
}

public static string BinaryToString(string data)
{
List<Byte> byteList = new List<Byte>();

for (int i = 0; i < data.Length; i += 8)
{
byteList.Add(Convert.ToByte(data.Substring(i, 8), 2));
}
return Encoding.ASCII.GetString(byteList.ToArray());
}
private void btnPullData_Click(object sender, EventArgs e)
{
string URI = "http://192.168.5.200:8888/api/Xamarin?email=jose%40gmail.com;

using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(URI);

var message = JsonConvert.DeserializeObject<SQLData>(json);

string clearpass = BinaryToString(message.pass);
MessageBox.Show(clearpass);
}

}









share|improve this question













marked as duplicate by dlatikay, Ken White, Community Nov 20 '18 at 1:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    Are you asking how to decode the SQL server string, or the c# string? The c# string looks like Base64 so see How do I decode a base64 encoded string?... yes, it's base64. Go to codebeautify.org/base64-decode and decode and you will get "Purple..." with a bunch of null characters appended.

    – dbc
    Nov 20 '18 at 1:15













  • @dbc - that is exactly what I needed!!! Thank you so much for that! It's all about knowing what to search for!

    – user2932408
    Nov 20 '18 at 1:22
















-1
















This question already has an answer here:




  • How do I decode a base64 encoded string?

    2 answers




I have a SQL Server database with a binary(64) column housing a password. I am using a C# ASP.NET API to query the data and return the data as a string back to my C# code.



In SQL Server the password is



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


In my C# the password as a string is



UHVycGxlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==


And in plain text the password is: Purple



My question at hand is how can I use C# to "parse" the returned string and convert it to readable format?



I tried the below syntax, but I get an error of... What would be the proper way to "parse" the hashed password into plain text?




Could not find any recognizable digits




public class SQLData
{
public string pass { get; set; }
}

public static string BinaryToString(string data)
{
List<Byte> byteList = new List<Byte>();

for (int i = 0; i < data.Length; i += 8)
{
byteList.Add(Convert.ToByte(data.Substring(i, 8), 2));
}
return Encoding.ASCII.GetString(byteList.ToArray());
}
private void btnPullData_Click(object sender, EventArgs e)
{
string URI = "http://192.168.5.200:8888/api/Xamarin?email=jose%40gmail.com;

using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(URI);

var message = JsonConvert.DeserializeObject<SQLData>(json);

string clearpass = BinaryToString(message.pass);
MessageBox.Show(clearpass);
}

}









share|improve this question













marked as duplicate by dlatikay, Ken White, Community Nov 20 '18 at 1:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    Are you asking how to decode the SQL server string, or the c# string? The c# string looks like Base64 so see How do I decode a base64 encoded string?... yes, it's base64. Go to codebeautify.org/base64-decode and decode and you will get "Purple..." with a bunch of null characters appended.

    – dbc
    Nov 20 '18 at 1:15













  • @dbc - that is exactly what I needed!!! Thank you so much for that! It's all about knowing what to search for!

    – user2932408
    Nov 20 '18 at 1:22














-1












-1








-1









This question already has an answer here:




  • How do I decode a base64 encoded string?

    2 answers




I have a SQL Server database with a binary(64) column housing a password. I am using a C# ASP.NET API to query the data and return the data as a string back to my C# code.



In SQL Server the password is



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


In my C# the password as a string is



UHVycGxlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==


And in plain text the password is: Purple



My question at hand is how can I use C# to "parse" the returned string and convert it to readable format?



I tried the below syntax, but I get an error of... What would be the proper way to "parse" the hashed password into plain text?




Could not find any recognizable digits




public class SQLData
{
public string pass { get; set; }
}

public static string BinaryToString(string data)
{
List<Byte> byteList = new List<Byte>();

for (int i = 0; i < data.Length; i += 8)
{
byteList.Add(Convert.ToByte(data.Substring(i, 8), 2));
}
return Encoding.ASCII.GetString(byteList.ToArray());
}
private void btnPullData_Click(object sender, EventArgs e)
{
string URI = "http://192.168.5.200:8888/api/Xamarin?email=jose%40gmail.com;

using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(URI);

var message = JsonConvert.DeserializeObject<SQLData>(json);

string clearpass = BinaryToString(message.pass);
MessageBox.Show(clearpass);
}

}









share|improve this question















This question already has an answer here:




  • How do I decode a base64 encoded string?

    2 answers




I have a SQL Server database with a binary(64) column housing a password. I am using a C# ASP.NET API to query the data and return the data as a string back to my C# code.



In SQL Server the password is



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


In my C# the password as a string is



UHVycGxlAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==


And in plain text the password is: Purple



My question at hand is how can I use C# to "parse" the returned string and convert it to readable format?



I tried the below syntax, but I get an error of... What would be the proper way to "parse" the hashed password into plain text?




Could not find any recognizable digits




public class SQLData
{
public string pass { get; set; }
}

public static string BinaryToString(string data)
{
List<Byte> byteList = new List<Byte>();

for (int i = 0; i < data.Length; i += 8)
{
byteList.Add(Convert.ToByte(data.Substring(i, 8), 2));
}
return Encoding.ASCII.GetString(byteList.ToArray());
}
private void btnPullData_Click(object sender, EventArgs e)
{
string URI = "http://192.168.5.200:8888/api/Xamarin?email=jose%40gmail.com;

using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString(URI);

var message = JsonConvert.DeserializeObject<SQLData>(json);

string clearpass = BinaryToString(message.pass);
MessageBox.Show(clearpass);
}

}




This question already has an answer here:




  • How do I decode a base64 encoded string?

    2 answers








c# json api






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 20 '18 at 1:06









user2932408user2932408

388




388




marked as duplicate by dlatikay, Ken White, Community Nov 20 '18 at 1:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by dlatikay, Ken White, Community Nov 20 '18 at 1:24


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Are you asking how to decode the SQL server string, or the c# string? The c# string looks like Base64 so see How do I decode a base64 encoded string?... yes, it's base64. Go to codebeautify.org/base64-decode and decode and you will get "Purple..." with a bunch of null characters appended.

    – dbc
    Nov 20 '18 at 1:15













  • @dbc - that is exactly what I needed!!! Thank you so much for that! It's all about knowing what to search for!

    – user2932408
    Nov 20 '18 at 1:22














  • 1





    Are you asking how to decode the SQL server string, or the c# string? The c# string looks like Base64 so see How do I decode a base64 encoded string?... yes, it's base64. Go to codebeautify.org/base64-decode and decode and you will get "Purple..." with a bunch of null characters appended.

    – dbc
    Nov 20 '18 at 1:15













  • @dbc - that is exactly what I needed!!! Thank you so much for that! It's all about knowing what to search for!

    – user2932408
    Nov 20 '18 at 1:22








1




1





Are you asking how to decode the SQL server string, or the c# string? The c# string looks like Base64 so see How do I decode a base64 encoded string?... yes, it's base64. Go to codebeautify.org/base64-decode and decode and you will get "Purple..." with a bunch of null characters appended.

– dbc
Nov 20 '18 at 1:15







Are you asking how to decode the SQL server string, or the c# string? The c# string looks like Base64 so see How do I decode a base64 encoded string?... yes, it's base64. Go to codebeautify.org/base64-decode and decode and you will get "Purple..." with a bunch of null characters appended.

– dbc
Nov 20 '18 at 1:15















@dbc - that is exactly what I needed!!! Thank you so much for that! It's all about knowing what to search for!

– user2932408
Nov 20 '18 at 1:22





@dbc - that is exactly what I needed!!! Thank you so much for that! It's all about knowing what to search for!

– user2932408
Nov 20 '18 at 1:22












1 Answer
1






active

oldest

votes


















0














First off, it's a terrible idea to store passwords in plain-text in the database. That said, the binary column of data from the database is in hex (base 16).



In your example, to convert



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


to Purple in C#, you could write:



Encoding.UTF8.GetString(yourByteArrayVariable).TrimEnd('0')


The TrimEnd is necessary because your column is a fixed width binary and not varbinary. As a result, it is right padded with the null character (0) and should be removed from the resulting string.






share|improve this answer
























  • I get a compile error of can not convert from string to byte.

    – user2932408
    Nov 20 '18 at 1:21











  • The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

    – Connor
    Nov 20 '18 at 1:23











  • if you look at my class SQLData I am converting it to String data type in C#

    – user2932408
    Nov 20 '18 at 1:24


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














First off, it's a terrible idea to store passwords in plain-text in the database. That said, the binary column of data from the database is in hex (base 16).



In your example, to convert



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


to Purple in C#, you could write:



Encoding.UTF8.GetString(yourByteArrayVariable).TrimEnd('0')


The TrimEnd is necessary because your column is a fixed width binary and not varbinary. As a result, it is right padded with the null character (0) and should be removed from the resulting string.






share|improve this answer
























  • I get a compile error of can not convert from string to byte.

    – user2932408
    Nov 20 '18 at 1:21











  • The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

    – Connor
    Nov 20 '18 at 1:23











  • if you look at my class SQLData I am converting it to String data type in C#

    – user2932408
    Nov 20 '18 at 1:24
















0














First off, it's a terrible idea to store passwords in plain-text in the database. That said, the binary column of data from the database is in hex (base 16).



In your example, to convert



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


to Purple in C#, you could write:



Encoding.UTF8.GetString(yourByteArrayVariable).TrimEnd('0')


The TrimEnd is necessary because your column is a fixed width binary and not varbinary. As a result, it is right padded with the null character (0) and should be removed from the resulting string.






share|improve this answer
























  • I get a compile error of can not convert from string to byte.

    – user2932408
    Nov 20 '18 at 1:21











  • The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

    – Connor
    Nov 20 '18 at 1:23











  • if you look at my class SQLData I am converting it to String data type in C#

    – user2932408
    Nov 20 '18 at 1:24














0












0








0







First off, it's a terrible idea to store passwords in plain-text in the database. That said, the binary column of data from the database is in hex (base 16).



In your example, to convert



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


to Purple in C#, you could write:



Encoding.UTF8.GetString(yourByteArrayVariable).TrimEnd('0')


The TrimEnd is necessary because your column is a fixed width binary and not varbinary. As a result, it is right padded with the null character (0) and should be removed from the resulting string.






share|improve this answer













First off, it's a terrible idea to store passwords in plain-text in the database. That said, the binary column of data from the database is in hex (base 16).



In your example, to convert



0x507572706C6500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000


to Purple in C#, you could write:



Encoding.UTF8.GetString(yourByteArrayVariable).TrimEnd('0')


The TrimEnd is necessary because your column is a fixed width binary and not varbinary. As a result, it is right padded with the null character (0) and should be removed from the resulting string.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 '18 at 1:18









ConnorConnor

581717




581717













  • I get a compile error of can not convert from string to byte.

    – user2932408
    Nov 20 '18 at 1:21











  • The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

    – Connor
    Nov 20 '18 at 1:23











  • if you look at my class SQLData I am converting it to String data type in C#

    – user2932408
    Nov 20 '18 at 1:24



















  • I get a compile error of can not convert from string to byte.

    – user2932408
    Nov 20 '18 at 1:21











  • The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

    – Connor
    Nov 20 '18 at 1:23











  • if you look at my class SQLData I am converting it to String data type in C#

    – user2932408
    Nov 20 '18 at 1:24

















I get a compile error of can not convert from string to byte.

– user2932408
Nov 20 '18 at 1:21





I get a compile error of can not convert from string to byte.

– user2932408
Nov 20 '18 at 1:21













The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

– Connor
Nov 20 '18 at 1:23





The datatype you have coming back from your database is probably not a byte then and is probably a string. Can you edit your post to include your code showing how you're getting the column from your database?

– Connor
Nov 20 '18 at 1:23













if you look at my class SQLData I am converting it to String data type in C#

– user2932408
Nov 20 '18 at 1:24





if you look at my class SQLData I am converting it to String data type in C#

– user2932408
Nov 20 '18 at 1:24



Popular posts from this blog

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

SQL update select statement

'app-layout' is not a known element: how to share Component with different Modules