Public Key Context

View: New views
5 Messages — Rating Filter:   Alert me  

Public Key Context

by Scott Neugroschl :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

OK, I'm probably a total idiot, but I'm can't figure this out.

In several places, the manual refers to a public-key context, but I
can't really find how to create said context when generating a key.

If I'm generating a key, and want to save the public key in a certificate,
is the public-key context merely the CRYPT_CONTEXT used to generate the key?

e.g.:

CRYPT_CONTEXT context;

cryptCreateContext(&context, CRYPT_UNUSED, CRYPT_ALGO_RSA);
cryptSetAttributeString(context, CRYPT_CTX_INFO_LABEL,
           "MY-KEY",6);
cryptGenerateKey(context);

At this point, is the variable "context" the public-key context?




_______________________________________________
Cryptlib mailing list
Cryptlib@... via Mail: cryptlib-request@...
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.

Re: Public Key Context

by BenjaminF :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

same thing here. how do I generate this public key context?
Scott Neugroschl wrote:
OK, I'm probably a total idiot, but I'm can't figure this out.

In several places, the manual refers to a public-key context, but I
can't really find how to create said context when generating a key.

If I'm generating a key, and want to save the public key in a certificate,
is the public-key context merely the CRYPT_CONTEXT used to generate the key?

e.g.:

CRYPT_CONTEXT context;

cryptCreateContext(&context, CRYPT_UNUSED, CRYPT_ALGO_RSA);
cryptSetAttributeString(context, CRYPT_CTX_INFO_LABEL,
           "MY-KEY",6);
cryptGenerateKey(context);

At this point, is the variable "context" the public-key context?




_______________________________________________
Cryptlib mailing list
Cryptlib@mbsks.franken.deAdministration via Mail: cryptlib-request@mbsks.franken.de
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.

Re: Public Key Context

by BenjaminF :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I also tried the cryptcontext but that does not work.

        int cryptContext = crypt.CreateContext(crypt.UNUSED, crypt.ALGO_RSA);
            crypt.SetAttributeString(cryptContext, crypt.CTXINFO_LABEL, "Private Key");
           // crypt.GenerateKey(cryptContext);

            //key stuff
            int keyset = crypt.KeysetOpen(crypt.UNUSED, crypt.KEYSET_FILE, "C:\\te.p15", crypt.KEYOPT_CREATE);
            crypt.AddPrivateKey(keyset, cryptContext, "password");
            crypt.SetAttribute(cryptcertificate, crypt.CERTINFO_SUBJECTPUBLICKEYINFO, cryptContext);

any suggestions?

Best Regards,

Benjamin

same thing here. how do I generate this public key context?
Scott Neugroschl wrote:
OK, I'm probably a total idiot, but I'm can't figure this out.

In several places, the manual refers to a public-key context, but I
can't really find how to create said context when generating a key.

If I'm generating a key, and want to save the public key in a certificate,
is the public-key context merely the CRYPT_CONTEXT used to generate the key?

e.g.:

CRYPT_CONTEXT context;

cryptCreateContext(&context, CRYPT_UNUSED, CRYPT_ALGO_RSA);
cryptSetAttributeString(context, CRYPT_CTX_INFO_LABEL,
           "MY-KEY",6);
cryptGenerateKey(context);

At this point, is the variable "context" the public-key context?




_______________________________________________
Cryptlib mailing list
Cryptlib@mbsks.franken.deAdministration via Mail: cryptlib-request@mbsks.franken.de
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.


Re: Public Key Context

by BenjaminF :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Peter,

I keep writing so I'm glad if you could help me this time. I wrote this code to test if I can use the certificate instead of the pubkeycontext because I don't know how to get it and in the end I also have to write a CA for Fraunhofer. Following is the code where I try to set the certificate as private key. Why does that not work? I have a similar problem when I want to decrypt with setting the private key. In the following are both functions.

greetings from Germany.

Benjamin

 private static byte[] encrypt(String message)
        {
 byte[] envelopedData = new byte[100];
            int bytescopied;
           
           
            int cryptContext = crypt.CreateContext(crypt.UNUSED, crypt.ALGO_RSA);
            crypt.SetAttributeString(cryptContext, crypt.CTXINFO_LABEL, "Private Key");
           

            int keyset = crypt.KeysetOpen(crypt.UNUSED, crypt.KEYSET_FILE, "C:\\tee.p15", crypt.KEYOPT_CREATE);
           
            crypt.GenerateKey(cryptContext);

            //key stuff
            int cryptcertificate = crypt.CreateCert(crypt.UNUSED, crypt.CERTTYPE_CERTIFICATE);
            crypt.SetAttribute(cryptcertificate, crypt.CERTINFO_SUBJECTPUBLICKEYINFO, cryptContext);
            crypt.SetAttributeString(cryptcertificate, crypt.CERTINFO_COMMONNAME, "Susanne");
            crypt.SetAttributeString(cryptcertificate, crypt.CERTINFO_COUNTRYNAME, "DE");
            crypt.SetAttributeString(cryptcertificate, crypt.CERTINFO_ORGANIZATIONNAME, "FHG");
            crypt.SetAttributeString(cryptcertificate, crypt.CERTINFO_ORGANISATIONALUNITNAME, "IAT");
           
           
            crypt.SetAttribute(cryptcertificate, crypt.CERTINFO_SELFSIGNED, 1);
            crypt.SetAttribute(cryptcertificate, crypt.CERTINFO_CA, 1);
           
           
           
            crypt.AddPrivateKey(keyset, cryptContext, "password");            
            crypt.SignCert(cryptcertificate, cryptContext);
            crypt.AddPublicKey(keyset, cryptcertificate);
             

            int cryptEnvelope = crypt.CreateEnvelope(crypt.UNUSED, crypt.FORMAT_CRYPTLIB);
            crypt.SetAttribute(cryptEnvelope, crypt.ENVINFO_PUBLICKEY, cryptcertificate);
            crypt.SetAttribute(cryptEnvelope, crypt.ENVINFO_DATASIZE, message.Length);
            bytescopied = crypt.PushData(cryptEnvelope, message);
            crypt.FlushData(cryptEnvelope);

            bytescopied = crypt.PopData(cryptEnvelope, envelopedData, envelopedData.Length);

            crypt.DestroyEnvelope(cryptEnvelope);
            crypt.KeysetClose(keyset);
            crypt.DestroyCert(cryptcertificate);
            crypt.DestroyContext(cryptContext);

            return envelopedData;
        }

   private static String decrypt(byte[] decmessage)
        {
            int bytescopied;
           
            int keyset = crypt.KeysetOpen(crypt.UNUSED, crypt.KEYSET_FILE, "C:\\tee.p15", crypt.KEYOPT_READONLY);
            int privkey = crypt.GetPrivateKey(keyset, crypt.KEYID_NAME, "Private Key", "password");
            byte[] messagebuffer = new Byte[decmessage.Length];

            int envelope = crypt.CreateEnvelope(crypt.UNUSED, crypt.FORMAT_AUTO);
           // crypt.SetAttribute(envelope, crypt.ENVINFO_KEYSET_DECRYPT, keyset );
            bytescopied = crypt.PushData(envelope, decmessage);
            crypt.FlushData(envelope);
            bytescopied = crypt.PopData(envelope, messagebuffer, messagebuffer.Length);
            crypt.DestroyEnvelope(envelope);

            return System.Text.Encoding.UTF8.GetString(messagebuffer);
        }


I also tried the cryptcontext but that does not work.

        int cryptContext = crypt.CreateContext(crypt.UNUSED, crypt.ALGO_RSA);
            crypt.SetAttributeString(cryptContext, crypt.CTXINFO_LABEL, "Private Key");
           // crypt.GenerateKey(cryptContext);

            //key stuff
            int keyset = crypt.KeysetOpen(crypt.UNUSED, crypt.KEYSET_FILE, "C:\\te.p15", crypt.KEYOPT_CREATE);
            crypt.AddPrivateKey(keyset, cryptContext, "password");
            crypt.SetAttribute(cryptcertificate, crypt.CERTINFO_SUBJECTPUBLICKEYINFO, cryptContext);

any suggestions?

Best Regards,

Benjamin
BenjaminF wrote:
same thing here. how do I generate this public key context?
Scott Neugroschl wrote:
OK, I'm probably a total idiot, but I'm can't figure this out.

In several places, the manual refers to a public-key context, but I
can't really find how to create said context when generating a key.

If I'm generating a key, and want to save the public key in a certificate,
is the public-key context merely the CRYPT_CONTEXT used to generate the key?

e.g.:

CRYPT_CONTEXT context;

cryptCreateContext(&context, CRYPT_UNUSED, CRYPT_ALGO_RSA);
cryptSetAttributeString(context, CRYPT_CTX_INFO_LABEL,
           "MY-KEY",6);
cryptGenerateKey(context);

At this point, is the variable "context" the public-key context?




_______________________________________________
Cryptlib mailing list
Cryptlib@mbsks.franken.deAdministration via Mail: cryptlib-request@mbsks.franken.de
Archive: ftp://ftp.franken.de/pub/crypt/cryptlib/archives/
http://news.gmane.org/gmane.comp.encryption.cryptlib
Posts from non-subscribed addresses are blocked to prevent spam, please
subscribe in order to post messages.

Re: Public Key Context

by BenjaminF :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I found a post from 2005 where someone tried something similiar. My problem is still that I can't add the private key that I added with

int privkeycontext = crypt.GetPrivateKey(keyset, crypt.KEYID_NAME, "Private Key", "password");
crypt.SetAttribute(envelope, crypt.ENVINFO_PRIVATEKEY, privkeycontext);


the post:
http://old.nabble.com/Can%27t-decrypt-with-private-key-td405683.html#a405683

I don't really get it, the context is the public key also? I thought my self-signed certificate is the public key?

Best Regards,

Benjamin