以下就是一个简单的示例,它从用户那里获得输入,然后进行 Base64 编码,最终显示编码的字符串。
#!/bin/bash#Sample program to take input, encode to base64 and display on terminal#Example by www.debugpoint.comecho "Enter text for encoding to base64:"read input_textoutput_text=`echo -n $input_text | base64`echo "The Base64 Encoded text is: $output_text"
如果存储的编码字符串与用户输入的文本再编码的字符串相匹配,则用户可以通过验证。虽然这是一种检查身份验证的很简单的方法,但有时这对一些简单的业务案例很有用。
#!/bin/bash#Sample program to take input, encode to base64 and display on terminal#Example by www.debugpoint.comecho "Type your password"read pwd1decoded_text=`echo 'U2lsZW5jZSBpcyBnb2xkZW4h' | base64 --decode`if [[ $pwd1 == $decoded_text ]]then echo "You are a valid user."else echo "You are NOT a valid user."fi