第七章 抽象IO / 7.4.4 md BIO

              #include <openssl/bio.h>

              #include <openssl/evp.h>

      

              int     main()

              {

                     BIO                      *bmd=NULL,*b=NULL;

                     const      EVP_MD*md=EVP_md5();

                     int                         len;

                     char               tmp[1024];

 

                     bmd=BIO_new(BIO_f_md());

                     BIO_set_md(bmd,md);

                     b= BIO_new(BIO_s_null());

                     b=BIO_push(bmd,b);

                     len=BIO_write(b,"openssl",7);

                     len=BIO_gets(b,tmp,1024);

                     BIO_free(b);

                     return 0;

       }

       说明:本示例用md BIO对字符串"opessl"进行md5摘要。

       bmd=BIO_new(BIO_f_md());生成一个md BIO

       BIO_set_md(bmd,md);设置md BIO md5 BIO

       b= BIO_new(BIO_s_null());生成一个null BIO

       b=BIO_push(bmd,b);构造BIO ,md5 BIO在顶部。

       len=BIO_write(b,"openssl",7);将字符串送入BIO做摘要。

       len=BIO_gets(b,tmp,1024);将摘要结果写入tmp缓冲区。