#!/usr/bin/env bash
generate_cashout_api_hash_key() {
local sum_of_amount_column="$1"
local first_row_iban="$2"
local first_row_amount="$3"
local first_row_currency="$4"
local first_row_gsm="$5"
local app_secret="$6"
first_row_gsm="${first_row_gsm//+/}"
local data="${sum_of_amount_column}|${first_row_iban}|${first_row_amount}|${first_row_currency}|${first_row_gsm}"
local rand1
rand1=$((RANDOM * RANDOM))
local iv
iv=$(printf "%s" "$rand1" | openssl sha1 | awk '{print $2}' | cut -c1-16)
local password
password=$(printf "%s" "$app_secret" | openssl sha1 | awk '{print $2}')
local rand2
rand2=$((RANDOM * RANDOM))
local salt
salt=$(printf "%s" "$rand2" | openssl sha1 | awk '{print $2}' | cut -c1-4)
local salt_with_password
salt_with_password=$(printf "%s" "${password}${salt}" | openssl sha256 | awk '{print $2}')
local key_ascii
key_ascii=$(printf "%s" "$salt_with_password" | cut -c1-32)
local key_hex
key_hex=$(printf "%s" "$key_ascii" | xxd -p -c 256)
local iv_hex
iv_hex=$(printf "%s" "$iv" | xxd -p -c 256)
local encrypted_base64
encrypted_base64=$(printf "%s" "$data" | openssl enc -aes-256-cbc -K "$key_hex" -iv "$iv_hex" -base64)
local msg="${iv}:${salt}:${encrypted_base64}"
msg="${msg//\//__}"
echo "$msg"
}
sum_of_amount_column="1000"
first_row_iban="TR331111111111111111111111"
first_row_amount="250"
first_row_currency="TRY"
first_row_gsm="+905123456789"
app_secret="myAppSecretKey"
hash_key=$(generate_cashout_api_hash_key \
"$sum_of_amount_column" \
"$first_row_iban" \
"$first_row_amount" \
"$first_row_currency" \
"$first_row_gsm" \
"$app_secret")
echo "Hash Key: $hash_key"{
"app_id": "6d4a7e9374a76c15260fcc75e315b0b9",
"app_secret": "b46a67571aa1e7ef5641dc3fa6f1712a",
"merchant_key": "$2y$10$HmRgYosneqcwHj.UH7upGuyCZqpQ1ITgSMj9Vvxn.t6f.Vdf2SQFO",
"pf_id": 39048,
"name": "John Doe",
"vkn": 7483494730,
"tckn": 83593451321,
"city": "Istanbul",
"address": "Sokak ABC, Istanbul, Turkey",
"iso_country_code": 742,
"post_code": 48400,
"site_url": "https://site.com",
"hash_key": "944357f199c09d70:1481:6ssfvYiTGF2iU3fYFI5F3A=="
}