zoukankan      html  css  js  c++  java
  • base64 和 md5

    概览

    1.base64和md5都可以通过apr-util库完成
    2.base64编码通过apr_base64_encode()实现
    3.md5编码通过apr_md5()实现

    正文

    1.安装apr库

    apt-get install libaprutil1
    

    2.base64编码

    apr base64官方文档

    #include <stdio.h>
    #include <string.h>
    #include<apr-1.0/apr_base64.h>
    #include<apr-1.0/apr_md5.h>
    #include<iostream>
    using namespace std;
    
    int main(){
        const unsigned char *str="hello";
        unsigned char decode_str[1000];
        int len = apr_base64_encode(decode_str,str, strlen(str));
        cout<<decode_str<<endl;
    return 0;
    }
    
    

    编译

    g++ test2.cpp -laprutil-1 -g -O0 -lpthread -lcrypt -fpermissive  -I/usr/include/apr-1.0
    

    md5编码

    apr-md5官方文档

    #include <stdio.h>
    #include <string.h>
    #include<apr-1.0/apr_base64.h>
    #include<apr-1.0/apr_md5.h>
    #include<iostream>
    
    using namespace std;
    
    int main(){
        const char *str="hello";
        unsigned char digest[128], digest_str[128];
        int len = apr_md5(digest, str, strlen(str));
        int x, i;
        unsigned int b;
        //散列出来的哈希值每个占8位,在实际过程中,不方便查看和对比(乱码),所以实际使用过程中,总是将md5值
        //一个8位的hash拆成两个4位,并映射到字符 0~9、a~z中
        for (x = i = 0; x < 16; x++) {
            b = (digest[x] >> 4) & 15;
            digest_str[i++] = b + (b > 9 ? 'a' - 10 : '0');
            b = digest[x] & 15;
            digest_str[i++] = b + (b > 9 ? 'a' - 10 : '0');
        }
        digest_str[i] = '';
        cout << digest_str <<endl;
        return 0;
    }
    

    编译

    g++ test2.cpp -laprutil-1 -g -O0 -lpthread -lcrypt -fpermissive  -I/usr/include/apr-1.0
    

    ref

    apr base64官方文档
    apr-md5官方文档

  • 相关阅读:
    记laravel项目,本地环境PHP7.1,线上PHP版本7.2,报错each函数废弃问题
    [教程] 《Mysql 实战 45 讲》
    PHP递归求和计算1加到n的和
    SSL原理
    PHP之抽象类与接口
    iOS调试之挂起线程
    iOS之Starfield
    iOS之透视效果
    CSS之框模型
    HTTP之CacheControl
  • 原文地址:https://www.cnblogs.com/ishen/p/12737229.html
Copyright © 2011-2022 走看看