3
PATH="$PATH":"$new_path"
5
file_primary_key_ctx=context.p_B1
6
file_rsaencrypt_key_pub=opuB1_B8
7
file_rsaencrypt_key_priv=oprB1_B8
8
file_rsaencrypt_key_ctx=context_loadext_out_B1_B8
9
file_rsadecrypt_key_ctx=context_load_out_B1_B8
10
file_rsaencrypt_key_name=name.load.B1_B8
12
file_rsa_en_output_data=rsa_en.out
13
file_rsa_de_output_data=rsa_de.out
14
file_input_data=secret.data
17
alg_primary_key=0x0001
18
alg_rsaencrypt_key=0x0001
20
if [ ! -e "$file_input_data" ]
22
echo "12345678" > $file_input_data
24
rm $file_primary_key_ctx $file_rsaencrypt_key_pub $file_rsaencrypt_key_priv $file_rsaencrypt_key_ctx $file_rsaencrypt_key_name $file_output_data $file_rsa_en_output_data $file_rsa_de_output_data -rf
28
tpm2_createprimary -A e -g $alg_hash -G $alg_primary_key -C $file_primary_key_ctx
30
echo "createprimary fail, please check the environment or parameters!"
33
tpm2_create -g $alg_hash -G $alg_rsaencrypt_key -o $file_rsaencrypt_key_pub -O $file_rsaencrypt_key_priv -c $file_primary_key_ctx
35
echo "create fail, please check the environment or parameters!"
38
tpm2_loadexternal -H n -u $file_rsaencrypt_key_pub -C $file_rsaencrypt_key_ctx
40
echo "loadexternal fail, please check the environment or parameters!"
43
tpm2_rsaencrypt -c $file_rsaencrypt_key_ctx -I $file_input_data -o $file_rsa_en_output_data
45
echo "rsa encrypt fail, please check the environment or parameters!"
49
tpm2_load -c $file_primary_key_ctx -u $file_rsaencrypt_key_pub -r $file_rsaencrypt_key_priv -n $file_rsaencrypt_key_name -C $file_rsadecrypt_key_ctx
51
echo "load fail, please check the environment or parameters!"
55
tpm2_rsadecrypt -c $file_rsadecrypt_key_ctx -I $file_rsa_en_output_data -o $file_rsa_de_output_data
57
echo "rsa decrypt fail, please check the environment or parameters!"