使用openssl产生随即数字串或字符串

it2022-05-05  110

–=使用openssl产生随即数字串或字符串===

使用openssl可以产生随即的字符串(数字字母都有) [root@nezhdb01 tmp]# openssl rand -base64 8 FpJl7yFuOcA= [root@nezhdb01 tmp]# openssl rand -base64 8 WOgWyanFDBc= [root@nezhdb01 tmp]# openssl rand -base64 8 |wc -m 13 [root@nezhdb01 tmp]# openssl rand -base64 8 |wc -m 13

可以随意调节字符串的长度 [root@nezhdb01 tmp]# openssl rand -base64 12 GF5PGFH0TwcHPM1C [root@nezhdb01 tmp]# openssl rand -base64 12 ijqpAYA4HJB+Pr8g [root@nezhdb01 tmp]# openssl rand -base64 12 |wc -m 17 [root@nezhdb01 tmp]# openssl rand -base64 12 |wc -m 17

可以执行tr命令,把数字全部转换为小写字母或者大写字母,生成字母串(里面会包含/+=) [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] rkxEiHiTGFhJOjcf [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] B/CqbFITrJfeeJyb [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] /flchxtfx/kZNDgY [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] Nb+YwhdSadMudD/Y

再次执行tr -d来删除特殊字符,这样就产生了纯字母串 [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] pUjPkFpozSsePfZQ [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] IeSjlkRmnYILjxr [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] UzhveJQZUdKzJfhC [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] MitjALZuhawzrSfJ

截取指定的字符串长度 [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] |cut -c 1-10 cCznbNIaII [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] |cut -c 1-10 KaabetInEg [root@nezhdb01 tmp]# openssl rand -base64 12 | tr [0-9] [a-z] | tr -d [/+=] |cut -c 1-10 InwmceQxft

利用md5sum可以生成随即的字符串(字母都是小写的) [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum b9a74931b434739770f51d7189b4ee54 - [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum 050078b503f8cfd6cc0ead7453334883 - [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum 063790af54bd32c6fa57da43ab27e554 -

转换为纯数字的串 [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum | tr [a-z] [0-9] 30014562242553345119431233629211 - [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum | tr [a-z] [0-9] 97301228550048435407014559052035 - [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum | tr [a-z] [0-9] 52044741250773514234210331437458 -

截取指定的字符串长度 [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum | tr [a-z] [0-9] |cut -c 1-10 0381238655 [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum | tr [a-z] [0-9] |cut -c 1-10 7947110211 [root@nezhdb01 tmp]# openssl rand -base64 12 | md5sum | tr [a-z] [0-9] |cut -c 1-10 6225354301


最新回复(0)