-
Notifications
You must be signed in to change notification settings - Fork 542
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
Error getting Content from CmsEnvelopedData with AES128-GCM #354
Comments
Hi! We are having exactly the same problem here. There is a clear difference with Java version and we are not sure about how to proceed here. Is there anyone who has fixed this issue without modifying the code? In the meanwhile, we are using this "fix" but we are not sure if this can have collateral effects in other parts of the library, so it would be nice if this could be discussed further and find a final solution for this bug. // /crypto/src/security/ParameterUtilities.cs
if (basicIVKeySize != -1 || canonical == "RIJNDAEL" || canonical == "SKIPJACK" || canonical == "TWOFISH")
{
var sequence = asn1Params as DerSequence;
iv = sequence != null ? ((DerOctetString) sequence[0]).GetOctets() : ((Asn1OctetString) asn1Params).GetOctets();
} EDIT: I added a PR with this fix. Maybe this could be fixed that way? #402 |
This should now be fixed and will be in the 2.1.0 release, expected shortly. |
Hello! |
I got a problem with decrypting
CmsEnvelopedData
that was encrypted with the bouncy castle library in JAVA.The error occurs when calling
var decryptedData = recipient.GetContent(privKey);
whererecipient
is of typeKeyTransRecipientInformation
.From what I could find out, the C# library is getting the IV Length from this line in
ParameterUtilities.cs
in the methodGetCipherParameters
:int basicIVKeySize = FindBasicIVSize(canonical);
In the case of
canonical
being "AES128" it will return 16.As long as
basicIVKeySize
is not -1 it will try to convert the parameter to an octetstring assuming that you only get the IV and not the IV Size:The Parameter inside of the
CmsEnvelopedData
, which was generated with the java library, seems to be:{[#1234567890abcdef12345678, 16]}
which obviously causes an exception when trying to convert it to
Asn1OctetString
, because its aDerSequence
instead.So in my opinion there are 2 things that could be the case:
Either
the java library shouldnt add the IV length when it can be derived from the algorithm
or
the c# library should check if it gets a
DerSequence
and convert it to IV & IV length if thats the caseShould also note that decrypting in java itself works just fine, but thats not what we want to use for decrypting.
We used:
Portable.BouncyCastle 1.9.0
The text was updated successfully, but these errors were encountered: