سؤال

I'm working with JSON-files and serializing. Well, so far I'm fine. Now, I have a question, I am signing data (bytes) with the RSA-class, so actually, I made a wrapper, but this is similar though. It returns a byte[] and now I want to serialize this byte[] to a JSON-file, where also other normals strings are in. But I have no idea how to start.

The signature must be within this JSON-document. My beginning was to convert the byte[] to a string and after that convert it back again.

public static string ConvertToString(byte[] input)
{
     System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
     return enc.GetString(input);
}

So, well I call it like that:

string signature = Converter.ConvertToString(new RsaSignature(PrivateKey).SignData(data));

So, this signs the given data and then should convert the returned byte[] to a string in order to serialize it, because, as I said, the rest of the JSON contains only strings.

Is there maybe a way to serialize the byte[] directly to it? Or how should I manage this.

Help is appreciated. Thanks!

هل كانت مفيدة؟

المحلول

You're looking for base64, which allows you to serialize arbitrary bytes to text.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top