Dieser Inhalt liegt nicht in Ihrer Sprache vor. Hier ist die englische Version.
Building a Linux shell script to convert clear text to Base64 encoding string
Talend
MetaServlet string needs to be encoded to Base64 when requesting Talend Administration Center
MetaServlet REST API.
To post a JSON script, take metaservlet - “addServer” as an example, as shown below. This
JSON sample adds a new Jobserver/Runtime server into Talend Administration Center
server page.
Encode the string by using the Linux shell script example shown below. Save the
script as base64url.sh file under /app repository (or at any location of your
preference).
#! /bin/bash
table=(A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 - _ =)
#text="{\"alg\":\"RS256\",\"typ\":\"JWT\"}"
#text="{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer.gserviceaccount.com\",\"scope\":\"https://www.googleapis.com/auth/prediction\",\"aud\":\"https://accounts.google.com/o/oauth2/token\",\"exp\":1328554385,\"iat\":1328550785}"
read text
# breaking binary represantation of $text in to 6-bit blocks
for line in $(echo -n "$text" | xxd -b -g 0 | cut -d ' ' -f 2 | paste -s -d '' | fold -w 6 -s)
do
length=$(echo ${#line})
let padding=6-$length
s="0"
p=""
# padding 6-bit to 8-bit by adding zeros to the right
if (($padding > 0)); then
while ((${#p} < "$padding")); do
p="$p$s";
done;
fi
# convert binary to decimal
n=$(echo "ibase=2;$line$p" | bc)
# output the table looked up character
echo -n ${table[n]}
done
Did this page help you?
If you find any issues with this page or its content – a typo, a missing step, or a technical error – please let us know!