/// <summary> /// Transforms a <see cref="SignedEntity"/> to the associated <see cref="SignedCms"/> instance /// </summary> /// <param name="entity">The <see cref="SignedEntity"/> to deserialize</param> /// <returns>The corresponding <see cref="SignedCms"/></returns> public SignedCms DeserializeDetachedSignature(SignedEntity entity) { if (entity == null) { throw new SignatureException(SignatureError.NullEntity); } // Serialize entity out as ASCII encoded... byte[] contentBytes = DefaultSerializer.Default.SerializeToBytes(entity.Content); byte[] signatureBytes = Convert.FromBase64String(entity.Signature.Body.Text); return(DeserializeDetachedSignature(contentBytes, signatureBytes)); }
/// <summary> /// Transforms a <see cref="SignedEntity"/> to the associated <see cref="SignedCms"/> instance /// </summary> /// <param name="entity">The <see cref="SignedEntity"/> to deserialize</param> /// <returns>The corresponding <see cref="SignedCms"/></returns> public SignedCms DeserializeDetachedSignature(SignedEntity entity) { if (entity == null) { throw new SignatureException(SignatureError.NullEntity); } // Serialize entity out as ASCII encoded... byte[] contentBytes = DefaultSerializer.Default.SerializeToBytes(entity.Content); byte[] signatureBytes = Convert.FromBase64String(entity.Signature.Body.Text); return DeserializeDetachedSignature(contentBytes, signatureBytes); }
//----------------------------------------------------- // // Signature Validation // //----------------------------------------------------- /// <summary> /// Checks that a signature was signed by the signer certificate. /// </summary> /// <param name="signedEntity">The signed entity to check</param> /// <param name="signerCertificate">The signer certificaet that purports to sign the entity</param> /// <exception cref="SignatureException">If the entity was not signed by the claimed certificate</exception> public void CheckSignature(SignedEntity signedEntity, X509Certificate2 signerCertificate) { SignedCms signatureEnvelope = DeserializeDetachedSignature(signedEntity); CheckSignature(signatureEnvelope.SignerInfos, signerCertificate); }