Currently I'm using com.google.common.io.BaseEncoding
class and running following command on Scala REPL to encode the array of bytes like this:
scala> com.google.common.io.BaseEncoding.base64().encode(Array.fill(16)((scala.util.Random.nextInt(256) - 128).toByte))
res5: String = zb6fgtoW404V259DLCg5sQ==
So far I've created some shell script for it:
#!/bin/bash
max_count=16
count=1
while [ "$count" -le $max_count ];
do
vector[$count]=$((RANDOM%256-128))
count=$((count+1))
done
echo $(IFS=' '; (echo "${vector[*]}") | base64) | tr -d ' '
But I want to create same logic as BaseEncoding.base64().encode()
method. Is it possible to convert array of bytes to encoded base64 string on Bash?