+2004-05-01 Sebastien Pouliot <sebastien@ximian.com>
+
+ * CryptoConvert.cs: Synched with Mono.Security.dll. Fix bug #57941
+ (truncated key pair).
+ * RSAManaged.cs: Synched with Mono.Security.dll. Fix bug #57941
+ (truncated key pair).
+
2004-04-28 Sebastien Pouliot <sebastien@ximian.com>
* CryptoConvert.cs: In sync with Mono.Security.dll version.
Array.Reverse (rsap.InverseQ);
pos += byteHalfLen;
- // BYTE privateExponent[rsapubkey.bitlen/8];
- rsap.D = new byte [byteLen];
- Buffer.BlockCopy (blob, pos, rsap.D, 0, byteLen);
- Array.Reverse (rsap.D);
+ // ok, this is hackish but CryptoAPI support it so...
+ // note: only works because CRT is used by default
+ // http://bugzilla.ximian.com/show_bug.cgi?id=57941
+ rsap.D = new byte [byteLen]; // must be allocated
+ if (pos + byteLen + offset <= blob.Length) {
+ // BYTE privateExponent[rsapubkey.bitlen/8];
+ Buffer.BlockCopy (blob, pos, rsap.D, 0, byteLen);
+ Array.Reverse (rsap.D);
+ }
RSA rsa = (RSA)RSA.Create ();
rsa.ImportParameters (rsap);
if ((d == null) || (p == null) || (q == null))
throw new CryptographicException ("Missing private key");
param.D = d.GetBytes ();
+ // hack for bugzilla #57941 where D wasn't provided
+ if (param.D.Length != param.Modulus.Length) {
+ byte[] normalizedD = new byte [param.Modulus.Length];
+ Buffer.BlockCopy (param.D, 0, normalizedD, (normalizedD.Length - param.D.Length), param.D.Length);
+ param.D = normalizedD;
+ }
param.P = p.GetBytes ();
param.Q = q.GetBytes ();
// but CRT parameters are optionals