I'm not sure I understand exactly what you want but you may find this useful.
var eByteString = eByte.Aggregate(string.Empty, (current, n) => current + n.ToString("000"));
var nByteString = nByte.Aggregate(string.Empty, (current, n) => current + n.ToString("000"));
or you can do it without extensions like:
//convert to decimal string
var eByteString = string.Empty;
foreach (byte b in eByte)
eByteString = eByteString + b.ToString("000");
var nByteString = string.Empty;
foreach (byte b in nByte)
nByteString = nByteString + b.ToString("000");
the result would be something like:
eByteString : 001000001
nByteString : 211110203128097225245156190057058005219074254110126137008162017185117098093007197199208188134068102171169132057218155254193154082182076214158032164159255142114232250019158058134077184026065093207059162082149098217128015167051030117204095144063074166219072006156228075166154194003029165048078213089138010151145220240249163048191014154160090207050215127170028113070212074123108011170137
These two lines convert both eByte
and nByte
to decimal representation of the byte array (every 3 character represents a single byte to make converting the string to original byte array possible).
to convert it back to byte array in c# you can use provided extension method:
static class Extensions
{
public static IEnumerable<String> SplitParts(this string text, int length)
{
for (var i = 0; i < text.Length; i += length)
yield return text.Substring(i, Math.Min(length, text.Length - i));
}
}
and conversion would be like:
var arr = eByteString.SplitParts(3).Select(s => Convert.ToByte(s)).ToArray();
here is the complete sample for convering to decimal string and back to byte array:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
namespace Test
{
static class Extensions
{
public static IEnumerable<String> SplitParts(this string text, int length)
{
for (var i = 0; i < text.Length; i += length)
yield return text.Substring(i, Math.Min(length, text.Length - i));
}
}
static class Program
{
static void Main()
{
RSA rsaObj = RSA.Create();
RSAParameters rsaParas = rsaObj.ExportParameters(false);
byte[] eByte = rsaParas.Exponent;
byte[] nByte = rsaParas.Modulus;
//convert to decimal string
var eByteString = eByte.Aggregate(string.Empty, (current, n) => current + n.ToString("000"));
var nByteString = nByte.Aggregate(string.Empty, (current, n) => current + n.ToString("000"));
//convert back to array
var arrEByteString = eByteString.SplitParts(3).Select(s => Convert.ToByte(s)).ToArray();
var arrNByteString = nByteString.SplitParts(3).Select(s => Convert.ToByte(s)).ToArray();
}
}
}