/// <summary> /// Check the type of signature and use the publicKeyDer to verify the /// signedBlob using the appropriate signature algorithm. /// </summary> /// /// <param name="signature"></param> /// <param name="signedBlob">the SignedBlob with the signed portion to verify.</param> /// <param name="publicKeyDer"></param> /// <returns>True if the signature is verified, false if failed.</returns> /// <exception cref="System.Security.SecurityException">if the signature type is not recognized or ifpublicKeyDer can't be decoded.</exception> protected static internal bool verifySignature( net.named_data.jndn.Signature signature, SignedBlob signedBlob, Blob publicKeyDer) { if (signature is Sha256WithRsaSignature) { if (publicKeyDer.isNull()) { return(false); } return(verifySha256WithRsaSignature(signature.getSignature(), signedBlob, publicKeyDer)); } else if (signature is Sha256WithEcdsaSignature) { if (publicKeyDer.isNull()) { return(false); } return(verifySha256WithEcdsaSignature(signature.getSignature(), signedBlob, publicKeyDer)); } else if (signature is DigestSha256Signature) { return(verifyDigestSha256Signature(signature.getSignature(), signedBlob)); } else { // We don't expect this to happen. throw new SecurityException( "PolicyManager.verify: Signature type is unknown"); } }
/// <summary> /// Check the type of signature and use the publicKeyDer to verify the /// signedBlob using the appropriate signature algorithm. /// </summary> /// /// <param name="signature"></param> /// <param name="signedBlob">the SignedBlob with the signed portion to verify.</param> /// <param name="publicKeyDer"></param> /// <returns>True if the signature is verified, false if failed.</returns> /// <exception cref="System.Security.SecurityException">if the signature type is not recognized or ifpublicKeyDer can't be decoded.</exception> protected static internal bool verifySignature( net.named_data.jndn.Signature signature, SignedBlob signedBlob, Blob publicKeyDer) { if (signature is Sha256WithRsaSignature || signature is Sha256WithEcdsaSignature) { if (publicKeyDer.isNull()) { return(false); } return(net.named_data.jndn.security.VerificationHelpers.verifySignature(signedBlob.signedBuf(), signature.getSignature(), new PublicKey(publicKeyDer), net.named_data.jndn.security.DigestAlgorithm.SHA256)); } else if (signature is DigestSha256Signature) { return(net.named_data.jndn.security.VerificationHelpers.verifyDigest(signedBlob.signedBuf(), signature.getSignature(), net.named_data.jndn.security.DigestAlgorithm.SHA256)); } else { // We don't expect this to happen. throw new SecurityException( "PolicyManager.verify: Signature type is unknown"); } }
/// <summary> /// Encode the signatureValue in the Signature object as a SignatureValue (the /// signature bits) in NDN-TLV and return the encoding. /// </summary> /// /// <param name="signature"></param> /// <returns>A Blob containing the encoding.</returns> public override Blob encodeSignatureValue(Signature signature) { TlvEncoder encoder = new TlvEncoder(256); encoder.writeBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.SignatureValue, signature.getSignature().buf()); return new Blob(encoder.getOutput(), false); }