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

–=使用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
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值