zoukankan      html  css  js  c++  java
  • crypto++ 使用Base64编码解码数组

    使用Crypto++库中的Base64Encoder、Base64Decoder编码解码数组。代码如下:

    //
    // Created by gj on 12/24/19.
    //
    #include <iostream>
    #include <crypto++/base64.h>
    #include <crypto++/sha.h>
    #include <crypto++/filters.h>
    #include <cryptopp/base64.h>
    
    using namespace std;
    using namespace CryptoPP;
    
    int main() {
        // "CBC Mode Test", without ''
        unsigned char plainText[] = {67, 66, 67, 32, 77, 111, 100, 101, 32, 84, 101, 115, 116};
    
        string encoded;
    
        Base64Encoder encoder;
        encoder.Put(plainText, sizeof(plainText));
        encoder.MessageEnd();
    
        word64 size = encoder.MaxRetrievable();
        if (size) {
            encoded.resize(size);
            encoder.Get((byte *) &encoded[0], encoded.size());
        }
    
        cout << encoded << endl;
    
        string decoded;
        Base64Decoder decoder;
        decoder.Put((byte *) encoded.data(), encoded.size());
        decoder.MessageEnd();
    
        size = decoder.MaxRetrievable();
        if (size && size <= SIZE_MAX) {
            decoded.resize(size);
            decoder.Get((byte *) &decoded[0], decoded.size());
        }
        cout << decoded << endl;
    
        return 0;
    }
    

      

  • 相关阅读:
    Java自学
    java自学
    每日总结
    每日总结
    每日总结
    每周总结
    每日总结
    每日总结
    每日总结
    每日总结
  • 原文地址:https://www.cnblogs.com/areful/p/12092235.html
Copyright © 2011-2022 走看看