Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for decoding OpenSSL RSA public keys in PEM format. #5

Merged
merged 3 commits into from
Mar 3, 2018

Conversation

LamarLugli
Copy link
Contributor

I added support for loading OpenSSL RSA public keys in PEM format.

You can generate the public key with OpenSSL using:
openssl rsa -in private.key -out public.key -pubout

I also bumped up the version number, so it is ready to publish a nuget package.

Copy link
Owner

@StefH StefH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this PR, can you please take a look at my comments ?

}
}

private static bool CompareByteArrays(byte[] arrayA, byte[] arrayB)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

internal static class DecoderUtils
{
internal static bool CompareByteArrays(byte[] arrayA, byte[] arrayB)
{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace content from this method by https://msdn.microsoft.com/en-us/library/bb348567.aspx if possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't do this because the library supports .Net Framework 2.0 and Linq is not supported.


internal static byte[] ExtractBytes(string text, string header, string footer)
{
var data = text;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

string


internal static int GetFieldLength(BinaryReader reader)
{
var bt = reader.ReadByte();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byte bt

var bytesToRead = bt & 0x0F;
var lengthArray = new byte[4];

for (var i = 4 - bytesToRead; i < 4; i++)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int i =

using (var reader = new BinaryReader(memoryStream))
{
var dataType = reader.ReadByte();
var fieldLength = DecoderUtils.GetFieldLength(reader);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int fieldLength

return default(RSAParameters);
}

var bt = reader.ReadByte();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byte bt

return default(RSAParameters);
}

var bitStreamLength = DecoderUtils.GetFieldLength(reader);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int bitStreamLength

return default(RSAParameters);
}

var dateType = reader.ReadByte();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

byte dateType

return default(RSAParameters);
}

var sequenceLength = DecoderUtils.GetFieldLength(reader);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int sequenceLength

@StefH
Copy link
Owner

StefH commented Mar 1, 2018

Thanks a lot for this PR, I've added some comments, can you take a look?

@LamarLugli
Copy link
Contributor Author

what's the reason against using var parameters on variables?

@StefH
Copy link
Owner

StefH commented Mar 1, 2018

Normally, I use only var for complex objects. And keep the type for primitives like : bool, int, byte, long, string and so on....

@StefH StefH merged commit 2f89e14 into StefH:master Mar 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants