Signing data

To prove that some data has come from someone we trust, it can be signed. Actually, you don't sign the data itself; instead, you sign a hash of the data. We will use the RSA algorithm combined with the SHA256 algorithm.

Signing with SHA256 and RSA

In the Ch11_CryptographyLib class library project, add the following code to the Protector class:

 public static string PublicKey; public static string ToXmlString( this RSA rsa, bool includePrivateParameters) { var p = rsa.ExportParameters(includePrivateParameters); XElement xml; if (includePrivateParameters) { xml = new XElement("RSAKeyValue" , new XElement("Modulus", Convert.ToBase64String(p.Modulus)) , new XElement("Exponent", Convert.ToBase64String(p.Exponent)) , new XElement("P", Convert.ToBase64String(p.P)) ...

Get C# 7 and .NET Core: Modern Cross-Platform Development - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.