Crypto with Digital Certificate

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Leandro H. Delamare

    #1

    Crypto with Digital Certificate

    Hello Group..
    Someone have a sample to how crypt a string using Crypto API with digital
    certificate ?

    If someone have a sample and can send to me :)

    Best Regards

    Leandro Delamare


  • Juan Gabriel Del Cid

    #2
    Re: Crypto with Digital Certificate

    Here's an example where you read a certificate from a local cert store and
    use it to sign some data. It's easy to modify it so you can encrypt/decrypt.

    I hope this helps,
    -JG


    /*************** *****
    * Cryptographer.c s *
    *************** *****/

    using System;
    using System.Security .Cryptography;
    using Microsoft.Web.S ervices.Securit y.X509;

    namespace Cryptomaniac {
    public class Crytographer {
    static void Main(string[] args) {
    RSACryptoServic eProvider rsa;

    // open the store
    X509Certificate Store store =
    X509Certificate Store.LocalMach ineStore("MySto re");

    store.OpenRead( );

    // get the cert
    X509Certificate Collection ccol =
    store.FindCerti ficateBySubject String("Test cert");

    X509Certificate cert = ccol[0];

    // construct the RSA object with which to sign the data
    rsa = (RSACryptoServi ceProvider)cert .Key;

    // get the bytes from the message (args[0] is the message)
    byte[] msg_bytes = System.Text.Enc oding.ASCII.Get Bytes(args[0]);

    // sign the data
    byte[] signature = rsa.SignData(ms g_bytes, "MD5");

    // show the data as a Base64 string
    Console.WriteLi ne("Signature: {0}",
    System.Convert. ToBase64String( signature));
    }
    }
    }


    Comment

    Working...