openssl - 获得public key

来源:百度文库 编辑:神马文学网 时间:2024/04/25 18:02:26
openssl - 获得public key2008-12-05 00:45

1)

int publen;
unsigned char *buf;
EVP_PKEY *key;
publen=i2d_PublicKey(key,NULL);//得到key的长度
buf=(unsigned char *)malloc(publen);
i2d_PublicKey(key,&buf);//PublicKey DER code

2)
#include

int RSA_private_encrypt(int flen, unsigned char *from,            unsigned char *to, RSA *rsa, int padding);
int RSA_public_decrypt(int flen, unsigned char *from,            unsigned char *to, RSA *rsa, int padding);

3)
#include

int RSA_public_encrypt(int flen, unsigned char *from,            unsigned char *to, RSA *rsa, int padding);
int RSA_private_decrypt(int flen, unsigned char *from,            unsigned char *to, RSA *rsa, int padding);
4) typedef struct rsa_st RSA;
5)struct evp_pkey_st
{
int type;
int save_type;
int references;
union {
   char *ptr;
#ifndef OPENSSL_NO_RSA
   struct rsa_st *rsa; /* RSA */
#endif
#ifndef OPENSSL_NO_DSA
   struct dsa_st *dsa; /* DSA */
#endif
#ifndef OPENSSL_NO_DH
   struct dh_st *dh; /* DH */
#endif
#ifndef OPENSSL_NO_EC
   struct ec_key_st *ec; /* ECC */
#endif
   } pkey;