echo -e " In ------ Out" 什么意思
时间: 2023-09-20 12:07:33 浏览: 125
这是一个 Linux 命令行中的输出语句,其中:
- `echo` 是一个命令,用于在终端输出文本。
- `-e` 是一个选项,用于启用转义字符的解释。
- `" In ------ Out"` 是要输出的文本内容,其中的 `\n` 表示换行。
因此,这个命令会输出以下内容:
```
In ------ Out
```
其中,`In` 和 `Out` 之间有一条横线,表示这是一个表格的头部。
相关问题
ec_sign_info_file="/tmp/ec_sign_info_file."$time_stamp ec_sign_info_sha256="/tmp/ec_sign_info_sha256."$time_stamp ec_binary_sign_file="/tmp/ec_binary_sign_file."$time_stamp /bin/echo -n "$1"_"$2" > $ec_sign_info_file openssl dgst -sha256 -binary -out $ec_sign_info_sha256 $ec_sign_info_file CheckStop $LINENO openssl pkeyutl -sign -in $ec_sign_info_sha256 -out $ec_binary_sign_file -inkey $3 -keyform PEM CheckStop $LINENO openssl base64 -e -in $ec_binary_sign_file -out $4 CheckStop $LINENO #rm $ec_sign_info_file $ec_sign_info_sha256 $ec_binary_sign_file echo "gen_ecdsa_sign succ sign_file_path:"$4
这是一个使用OpenSSL库在Linux上实现ECDSA签名的脚本的一部分,它包括以下步骤:
1. 创建一个临时文件来存储要签名的信息。
2. 使用OpenSSL的dgst命令计算信息的SHA256哈希值,并将其写入另一个临时文件。
3. 使用OpenSSL的pkeyutl命令使用私钥对哈希进行签名,并将签名写入第三个临时文件。
4. 使用OpenSSL的base64命令将签名编码为Base64格式,并将其写入最终的签名文件。
5. 最后,这个脚本打印一个成功消息,并返回签名文件的路径。
请注意,这个脚本仅是ECDSA签名的示例,并且在实际应用中需要更多的安全措施和步骤。
转python写法:#!/bin/sh time_stamp=`date +%s` function CheckStop() { if [ $? -ne 0 ]; then echo "execute fail, error on line_no:"$1" exit!!!" exit fi } function GenEcdsaKey() { ec_param_file_path="/tmp/ec_param.pem."$time_stamp openssl ecparam -out $ec_param_file_path -name prime256v1 -genkey CheckStop $LINENO openssl genpkey -paramfile $ec_param_file_path -out $1 CheckStop $LINENO openssl pkey -in $1 -inform PEM -out $2 -outform PEM -pubout CheckStop $LINENO rm $ec_param_file_path echo "gen_ecdsa_key succ prikey_path:"$1" pubkey_path:"$2 } function GenEcdsaSign() { ec_sign_info_file="/tmp/ec_sign_info_file."$time_stamp ec_sign_info_sha256="/tmp/ec_sign_info_sha256."$time_stamp ec_binary_sign_file="/tmp/ec_binary_sign_file."$time_stamp echo -n "$1"_"$2" > $ec_sign_info_file openssl dgst -sha256 -binary -out $ec_sign_info_sha256 $ec_sign_info_file CheckStop $LINENO openssl pkeyutl -sign -in $ec_sign_info_sha256 -out $ec_binary_sign_file -inkey $3 -keyform PEM CheckStop $LINENO openssl base64 -e -in $ec_binary_sign_file -out $4 CheckStop $LINENO rm $ec_sign_info_file $ec_sign_info_sha256 $ec_binary_sign_file echo "gen_ecdsa_sign succ sign_file_path:"$4 } function VerifyEcdsaSign() { ec_sign_info_file="/tmp/ec_sign_info_file."$time_stamp ec_sign_info_sha256="/tmp/ec_sign_info_sha256."$time_stamp ec_binary_sign_file="/tmp/ec_binary_sign_file."$time_stamp echo -n "$1"_"$2" > $ec_sign_info_file openssl dgst -sha256 -binary -out $ec_sign_info_sha256 $ec_sign_info_file CheckStop $LINENO openssl base64 -d -in $4 -out $ec_binary_sign_file CheckStop $LINENO openssl pkeyutl -verify -in $ec_sign_info_sha256 -sigfile $ec_binary_sign_file -pubin -inkey $3 -keyform PEM rm $ec_sign_info_file $ec_sign_info_sha256 $ec_binary_sign_file } function Usage() { echo "Usage:" echo "mmiot_ecdsa_sign.sh gen_ecdsa_key <private_key_file_path> <public_key_file_path>" echo "mmiot_ecdsa_sign.sh gen_ecdsa_sign <product_id> <sn> <private_
以下是转换后的 Python 代码:
```python
#!/usr/bin/env python
import os
import subprocess
import base64
time_stamp = str(int(time.time()))
def check_stop(line_no, ret):
if ret != 0:
print("execute fail, error on line_no: ", line_no, " exit!!!")
exit()
def gen_ecdsa_key(private_key_file_path, public_key_file_path):
ec_param_file_path = "/tmp/ec_param.pem." + time_stamp
ret = subprocess.call(["openssl", "ecparam", "-out", ec_param_file_path, "-name", "prime256v1", "-genkey"])
check_stop(sys._getframe().f_lineno, ret)
ret = subprocess.call(["openssl", "genpkey", "-paramfile", ec_param_file_path, "-out", private_key_file_path])
check_stop(sys._getframe().f_lineno, ret)
ret = subprocess.call(["openssl", "pkey", "-in", private_key_file_path, "-inform", "PEM", "-out", public_key_file_path, "-outform", "PEM", "-pubout"])
check_stop(sys._getframe().f_lineno, ret)
os.remove(ec_param_file_path)
print("gen_ecdsa_key succ prikey_path:", private_key_file_path, " pubkey_path:", public_key_file_path)
def gen_ecdsa_sign(product_id, sn, private_key_file_path, sign_file_path):
ec_sign_info_file = "/tmp/ec_sign_info_file." + time_stamp
ec_sign_info_sha256 = "/tmp/ec_sign_info_sha256." + time_stamp
ec_binary_sign_file = "/tmp/ec_binary_sign_file." + time_stamp
with open(ec_sign_info_file, 'w') as f:
f.write(product_id + "_" + sn)
ret = subprocess.call(["openssl", "dgst", "-sha256", "-binary", "-out", ec_sign_info_sha256, ec_sign_info_file])
check_stop(sys._getframe().f_lineno, ret)
ret = subprocess.call(["openssl", "pkeyutl", "-sign", "-in", ec_sign_info_sha256, "-out", ec_binary_sign_file, "-inkey", private_key_file_path, "-keyform", "PEM"])
check_stop(sys._getframe().f_lineno, ret)
with open(ec_binary_sign_file, 'rb') as f:
sign_binary = f.read()
sign_base64 = base64.b64encode(sign_binary).decode()
with open(sign_file_path, 'w') as f:
f.write(sign_base64)
os.remove(ec_sign_info_file)
os.remove(ec_sign_info_sha256)
os.remove(ec_binary_sign_file)
print("gen_ecdsa_sign succ sign_file_path:", sign_file_path)
def verify_ecdsa_sign(product_id, sn, public_key_file_path, sign_file_path):
ec_sign_info_file = "/tmp/ec_sign_info_file." + time_stamp
ec_sign_info_sha256 = "/tmp/ec_sign_info_sha256." + time_stamp
ec_binary_sign_file = "/tmp/ec_binary_sign_file." + time_stamp
with open(ec_sign_info_file, 'w') as f:
f.write(product_id + "_" + sn)
ret = subprocess.call(["openssl", "dgst", "-sha256", "-binary", "-out", ec_sign_info_sha256, ec_sign_info_file])
check_stop(sys._getframe().f_lineno, ret)
with open(sign_file_path, 'r') as f:
sign_base64 = f.read()
sign_binary = base64.b64decode(sign_base64)
with open(ec_binary_sign_file, 'wb') as f:
f.write(sign_binary)
ret = subprocess.call(["openssl", "pkeyutl", "-verify", "-in", ec_sign_info_sha256, "-sigfile", ec_binary_sign_file, "-pubin", "-inkey", public_key_file_path, "-keyform", "PEM"])
os.remove(ec_sign_info_file)
os.remove(ec_sign_info_sha256)
os.remove(ec_binary_sign_file)
print("verify_ecdsa_sign result:", "succ" if ret == 0 else "fail")
if len(sys.argv) < 2:
print("Usage:")
print("python mmiot_ecdsa_sign.py gen_ecdsa_key <private_key_file_path> <public_key_file_path>")
print("python mmiot_ecdsa_sign.py gen_ecdsa_sign <product_id> <sn> <private_key_file_path> <sign_file_path>")
print("python mmiot_ecdsa_sign.py verify_ecdsa_sign <product_id> <sn> <public_key_file_path> <sign_file_path>")
exit()
if sys.argv[1] == "gen_ecdsa_key":
gen_ecdsa_key(sys.argv[2], sys.argv[3])
elif sys.argv[1] == "gen_ecdsa_sign":
gen_ecdsa_sign(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
elif sys.argv[1] == "verify_ecdsa_sign":
verify_ecdsa_sign(sys.argv[2], sys.argv[3], sys.argv[4], sys.argv[5])
else:
print("Usage:")
print("python mmiot_ecdsa_sign.py gen_ecdsa_key <private_key_file_path> <public_key_file_path>")
print("python mmiot_ecdsa_sign.py gen_ecdsa_sign <product_id> <sn> <private_key_file_path> <sign_file_path>")
print("python mmiot_ecdsa_sign.py verify_ecdsa_sign <product_id> <sn> <public_key_file_path> <sign_file_path>")
```
阅读全文