static int GetRSAPublicKeySize(byte[] kv) { AsnElt ae = AsnElt.Decode(kv); ae.CheckTag(AsnElt.SEQUENCE); ae.CheckNumSub(2); AsnElt ai = ae.GetSub(0); ai.CheckTag(AsnElt.INTEGER); ai.CheckPrimitive(); byte[] v = ai.CopyValue(); if (v.Length > 0 && v[0] >= 0x80) { throw new AsnException( "Invalid RSA modulus (negative)"); } int bitLen = M.BitLength(v); if (bitLen < 512) { throw new AsnException(string.Format( "Invalid RSA modulus ({0} bits)", bitLen)); } else if ((v[v.Length - 1] & 0x01) == 0) { throw new AsnException("Invalid RSA modulus (even)"); } return(bitLen); }