/// <summary> /// Validate ephemeral public key signature. /// </summary> /// <param name="data">Data to validate.</param> /// <param name="sign">Sign</param> /// <param name="publicSigningKey">Public Signing key from other party.</param> /// <returns>Is verify succeeded.</returns> public static bool ValidateEphemeralPublicKeySignature( byte[] data, byte[] sign, GXPublicKey publicSigningKey) { GXAsn1Integer a = new GXAsn1Integer(sign, 0, 32); GXAsn1Integer b = new GXAsn1Integer(sign, 32, 32); GXAsn1Sequence s = new GXAsn1Sequence(); s.Add(a); s.Add(b); byte[] tmp = GXAsn1Converter.ToByteArray(s); GXEcdsa c = new GXEcdsa(publicSigningKey); bool ret = c.Verify(sign, data); if (!ret) { System.Diagnostics.Debug.WriteLine("Data:" + GXCommon.ToHex(data, true)); System.Diagnostics.Debug.WriteLine("Sign:" + GXCommon.ToHex(sign, true)); } return(ret); }
/// <summary> /// Get public key as encoded format. /// </summary> /// <returns></returns> public byte[] ToEncoded() { //Subject Public Key Info. GXAsn1Sequence d = new GXAsn1Sequence(); GXAsn1Sequence d1 = new GXAsn1Sequence(); d1.Add(new GXAsn1ObjectIdentifier("1.2.840.10045.2.1")); if (Scheme == Ecc.P256) { d1.Add(new GXAsn1ObjectIdentifier("1.2.840.10045.3.1.7")); } else if (Scheme == Ecc.P384) { d1.Add(new GXAsn1ObjectIdentifier("1.3.132.0.34")); } else { throw new Exception("Invalid ECC scheme."); } d.Add(d1); d.Add(new GXAsn1BitString(RawValue, 0)); return(GXAsn1Converter.ToByteArray(d)); }
public string ToDer() { GXAsn1Sequence d = new GXAsn1Sequence(); d.Add((sbyte)CertificateVersion.Version2); d.Add(RawValue); GXAsn1Sequence d1 = new GXAsn1Sequence(); if (Scheme == Ecc.P256) { d1.Add(new GXAsn1ObjectIdentifier("1.2.840.10045.3.1.7")); } else if (Scheme == Ecc.P384) { d1.Add(new GXAsn1ObjectIdentifier("1.3.132.0.34")); } else { throw new Exception("Invalid ECC scheme."); } d.Add(d1); d.Add(new GXAsn1BitString(GetPublicKey().RawValue)); return(GXCommon.ToBase64(GXAsn1Converter.ToByteArray(d))); }