Hi All, I'm having a bit of a problem. I need to load a private key (EC, but I'm having the same problem with RSA) from an unecrypted, der encoded, PKCS8 memory buffer. I'm just trying to get it to work loading from a file for now and it's simply not working. Can someone tell me what I'm doing wrong?
I'm generating the key like this: openssl ecparam -name sect571r1 -genkey | openssl pkcs8 -topk8 -nocrypt -inform pem -outform der -out ec_key.pk8 And my little test program is this: #include <errno.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <openssl/pem.h> #include <openssl/evp.h> #include <openssl/ssl.h> int main(int argc, char **argv) { OpenSSL_add_all_algorithms(); SSL_load_error_strings(); FILE *f = fopen(argv[1], "r"); if(f == NULL) { printf("File open failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } EVP_PKEY *key = d2i_PKCS8PrivateKey_fp(f, NULL, NULL, NULL); if(key == NULL) { ERR_print_errors_fp(stdout); exit(EXIT_FAILURE); } } The output is this: 3074066056:error:0D0680A8:asn1 encoding routines:ASN1_CHECK_TLEN:wrong tag:tasn_dec.c:1319: 3074066056:error:0D07803A:asn1 encoding routines:ASN1_ITEM_EX_D2I:nested asn1 error:tasn_dec.c:381:Type=X509_ALGOR 3074066056:error:0D08303A:asn1 encoding routines:ASN1_TEMPLATE_NOEXP_D2I:nested asn1 error:tasn_dec.c:751:Field=algor, Type=X509_SIG I apologize in advance for the giant corporate spew attached to this message. Ken Allen Senior Software Engineer ESS Division Ultra Electronics, Prologic 15 E. Main St. Westminster, MD 21157 ken.al...@ultra-prologic.com Tel: +1 410 203 1103 Fax: +1 410 203 1151 www.ultra-prologic.com This e-mail from Ultra Electronics, ProLogic and any attachments to it are confidential to the intended recipient and may also be privileged or controlled by U.S. export control laws and regulations. No technical data, information or other items provided by Ultra Electronics, ProLogic in connection with this email shall be shared or provided to any foreign persons, entities, or subsidiaries without the expressed written authorization of Ultra Electronic, ProLogic. If you have received it in error please notify the sender and delete it from your system. If you are not the intended recipient you must not copy it or use it for any purpose nor disclose or distribute its contents to any other person. All communications may be subject to interception or monitoring for operational and/or security purposes. Please rely on your own virus checking as the sender cannot accept any liability for any damage arising from any bug or virus infection. Please consider the environment before printing this email. ______________________________________________________________________ OpenSSL Project http://www.openssl.org User Support Mailing List openssl-users@openssl.org Automated List Manager majord...@openssl.org