jackwener commented on a change in pull request #8277: URL: https://github.com/apache/incubator-doris/pull/8277#discussion_r816606898
########## File path: be/src/util/encryption_util.cpp ########## @@ -219,21 +230,30 @@ static int do_decrypt(EVP_CIPHER_CTX* cipher_ctx, const EVP_CIPHER* cipher, int EncryptionUtil::decrypt(EncryptionMode mode, const unsigned char* encrypt, uint32_t encrypt_length, const unsigned char* key, uint32_t key_length, - const unsigned char* iv, bool padding, unsigned char* decrypt_content) { + const char* iv_str, bool padding, unsigned char* decrypt_content) { const EVP_CIPHER* cipher = get_evp_type(mode); /* The encrypt key to be used for decryption */ unsigned char encrypt_key[ENCRYPTION_MAX_KEY_LENGTH / 8]; create_key(key, key_length, encrypt_key, mode); - if (cipher == nullptr || (EVP_CIPHER_iv_length(cipher) > 0 && !iv)) { + int iv_length = EVP_CIPHER_iv_length(cipher); + if (cipher == nullptr || (iv_length > 0 && !iv_str)) { return AES_BAD_DATA; } + char* init_vec = nullptr; + std::string iv_default("DORISDORISDORIS_"); + + if (iv_str) { + init_vec = &iv_default[0]; + memcpy(init_vec, iv_str, strnlen(iv_str, EVP_MAX_IV_LENGTH)); + init_vec[iv_length] = '\0'; + } EVP_CIPHER_CTX* cipher_ctx = EVP_CIPHER_CTX_new(); EVP_CIPHER_CTX_reset(cipher_ctx); int length = 0; - int ret = do_decrypt(cipher_ctx, cipher, encrypt, encrypt_length, encrypt_key, iv, padding, - decrypt_content, &length); + int ret = do_decrypt(cipher_ctx, cipher, encrypt, encrypt_length, encrypt_key, + (unsigned char*)init_vec, padding, decrypt_content, &length); Review comment: reinterpret_cast may be better? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org