-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Conversation
There was a problem hiding this 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 ?
examples/ConsoleAppNetCore/Demo.cs
Outdated
} | ||
} | ||
|
||
private static bool CompareByteArrays(byte[] arrayA, byte[] arrayB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use https://msdn.microsoft.com/en-us/library/bb348567.aspx for this.
internal static class DecoderUtils | ||
{ | ||
internal static bool CompareByteArrays(byte[] arrayA, byte[] arrayB) | ||
{ |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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++) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int sequenceLength
Thanks a lot for this PR, I've added some comments, can you take a look? |
what's the reason against using var parameters on variables? |
Normally, I use only |
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.