public static SqlBoolean verifySignature(SqlString keySize, SqlString PublicKey, SqlString message, SqlString signature) { byte[] messageBytes = Encoding.ASCII.GetBytes(message.ToString()); byte[] signatureBytes = Convert.FromBase64String(signature.ToString()); X9ECParameters ecParams = NistNamedCurves.GetByName("P-" + keySize.ToString()); ECDomainParameters domainParameters = new ECDomainParameters(ecParams.Curve, ecParams.G, ecParams.N, ecParams.H, ecParams.GetSeed()); var G = ecParams.G; Org.BouncyCastle.Math.EC.ECCurve curve = ecParams.Curve; byte[] encoded = Convert.FromBase64String(PublicKey.ToString()); ECPoint q = curve.DecodePoint(encoded); try { ECPublicKeyParameters pubkeyParam = new ECPublicKeyParameters(q, domainParameters); var verifier = SignerUtilities.GetSigner("ECDSA"); verifier.Init(false, pubkeyParam); verifier.BlockUpdate(messageBytes, 0, messageBytes.Length); bool signatureOK = verifier.VerifySignature(signatureBytes); return(signatureOK); } catch { return(false); } }
public static ECPoint CleanPoint(ECCurve c, ECPoint p) { ECCurve cp = p.Curve; if (!c.Equals(cp)) { throw new ArgumentException("Point must be on the same curve", "p"); } return(c.DecodePoint(p.GetEncoded(false))); }
public X9ECPoint( ECCurve c, Asn1OctetString s) { this.p = c.DecodePoint(s.GetOctets()); }
public static ECPoint DeserializeECPoint(byte[] ecPointFormats, ECCurve curve, byte[] encoding) { if (encoding == null || encoding.Length < 1) throw new TlsFatalAlert(AlertDescription.illegal_parameter); byte actualFormat; switch (encoding[0]) { case 0x02: // compressed case 0x03: // compressed { if (ECAlgorithms.IsF2mCurve(curve)) { actualFormat = ECPointFormat.ansiX962_compressed_char2; } else if (ECAlgorithms.IsFpCurve(curve)) { actualFormat = ECPointFormat.ansiX962_compressed_prime; } else { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } break; } case 0x04: // uncompressed { actualFormat = ECPointFormat.uncompressed; break; } case 0x00: // infinity case 0x06: // hybrid case 0x07: // hybrid default: throw new TlsFatalAlert(AlertDescription.illegal_parameter); } if (actualFormat != ECPointFormat.uncompressed && (ecPointFormats == null || !Arrays.Contains(ecPointFormats, actualFormat))) { throw new TlsFatalAlert(AlertDescription.illegal_parameter); } return curve.DecodePoint(encoding); }