Has anybody got this to work?
I used the C# code provided in this thread to get the base64 string and when I use the github sa-license-decoder all the fields are empty.
Here are my code:
private static byte[] GetPaddedValue(BigInteger value, int length)
{
byte[] result = value.ToByteArrayUnsigned();
byte[] padded = new byte[length];
Buffer.BlockCopy(result, 0, padded, (length - result.Length), result.Length);
return padded;
}
private static byte[] HexToByteArray(string hex)
{
return Enumerable.Range(0, hex.Length)
.Where(x => x % 2 == 0)
.Select(x => Convert.ToByte(hex.Substring(x, 2), 16))
.ToArray();
}
private static byte[] EncryptValue(byte[] rgb, BigInteger e, BigInteger n, int size)
{
BigInteger input = new BigInteger(rgb);
BigInteger output = input.ModPow(e, n);
byte[] result = GetPaddedValue(output, size);
return result;
}
public static void Main(string[] args)
{
string longKey = @"-----BEGIN RSA PUBLIC KEY-----
MIGWAoGBAMqfGO9sPz+kxaRh/qVKsZQGul7NdG1gonSS3KPXTjtcHTFfexA4MkGA
mwKeu9XeTRFgMMxX99WmyaFvNzuxSlCFI/foCkx0TZCFZjpKFHLXryxWrkG1Bl9+
+gKTvTJ4rWk1RvnxYhm3n/Rxo2NoJM/822Oo7YBZ5rmk8NuJU4HLAhAYcJLaZFTO
sYU+aRX4RmoF
-----END RSA PUBLIC KEY-----";
string input = "019b09450000..."; //Took the rest out due to security reasons
using (var reader = new StringReader(longKey))
{
var pem = new PemReader(reader);
var o = (RsaKeyParameters)pem.ReadObject();
var bytes = HexToByteArray(input);
byte[] newArray = new byte[128];
Array.Copy(bytes, 6, newArray, 0, 128); // Remove first 6 bytes, take next 128 bytes
var decrypted = EncryptValue(newArray, o.Exponent, o.Modulus, 128);
string base64 = Convert.ToBase64String(decrypted);
string ascii = Encoding.ASCII.GetString(decrypted);
Console.WriteLine("As base64: " + base64);
Console.WriteLine("As ASCII: " + ascii);
}
}
PS: This line var br = new BinaryReader(HexToByteArray(input)); gives an error Cannot convert byte[] to stream. So I made a slight change to remove the first 6 bytes and then take only the next 128 bytes.