diff --git a/src/share/ob_encryption_util.h b/src/share/ob_encryption_util.h index 4c0e447b2..940b3979e 100644 --- a/src/share/ob_encryption_util.h +++ b/src/share/ob_encryption_util.h @@ -32,6 +32,7 @@ class ObKeyGenerator { public: static int generate_encrypt_key(char *buf, int64_t len); + static int generate_encrypt_key_char(char *buf, int64_t len); }; enum ObCipherOpMode { diff --git a/src/share/ob_encryption_util_os.cpp b/src/share/ob_encryption_util_os.cpp index 3b6b131e4..c2261b7ea 100644 --- a/src/share/ob_encryption_util_os.cpp +++ b/src/share/ob_encryption_util_os.cpp @@ -46,6 +46,31 @@ int ObKeyGenerator::generate_encrypt_key(char *buf, int64_t len) return ret; } +int ObKeyGenerator::generate_encrypt_key_char(char *buf, int64_t len) +{ + int ret = OB_SUCCESS; + if (len <= 0) { + ret = OB_INVALID_ARGUMENT; + LOG_WARN("the buf of len is invalid", K(ret)); + } else { + int i; + for (i = 0; i < len; ++i) { + switch (common::ObRandom::rand(0, 2)) { + case 1: + buf[i] = 'A' + common::ObRandom::rand(0, 25); + break; + case 2: + buf[i] = 'a' + common::ObRandom::rand(0, 25); + break; + default: + buf[i] = '0' + common::ObRandom::rand(0, 9); + break; + } + } + } + return ret; +} + static const EVP_CIPHER *get_evp_cipher(const ObCipherOpMode mode) { switch (mode)