- Mysql Query ใน Codeigniter model
function aes_encrypt($data,$key) { $sql = "SELECT AES_ENCRYPT(?,?) AS enc_data ;"; $query = $this->db->query( $sql , array($data,$key)); if ($query->num_rows() >= 1) { $row = $query->row(); return $row->enc_data; } return NULL; } function aes_decrypt($data,$key) { $sql = "SELECT AES_DECRYPT(?,?) AS dec_data ;"; $query = $this->db->query( $sql , array($data,$key)); if ($query->num_rows() >= 1) { $row = $query->row(); return $row->dec_data; } return NULL; }
- C++ ใช้ CryptoPP Library
//Rijndael //128bit //Mode: ECB #define CRYPTOPP_ENABLE_NAMESPACE_WEAK 1 #include "cryptlib.h" #include "aes.h" #include "channels.h" #include "files.h" #include "modes.h" #include "rng.h" #include "default.h" //------------ byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ]; ZeroMemory( key, CryptoPP::AES::DEFAULT_KEYLENGTH ); ZeroMemory( iv, CryptoPP::AES::BLOCKSIZE ); //Key example = 0000000000000000 memcpy(key,"0000000000000000",CryptoPP::AES::DEFAULT_KEYLENGTH); CryptoPP::AES::Encryption aesEncryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH); CryptoPP::ECB_Mode_ExternalCipher::Encryption ecbEncryption( aesEncryption, iv ); std::string _plaintext = ""; std::string _encrypt; CryptoPP::StringSource( _plaintext , true, new CryptoPP::StreamTransformationFilter( ecbEncryption, new CryptoPP::StringSink( _encrypt) ) );
อ่านเพิ่มโหมดอื่นที่ไม่ใช่ ECB http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation
ไม่มีความคิดเห็น:
แสดงความคิดเห็น