Answer the question
In order to leave comments, you need to log in
What is the correct way to write from PHP hex2bin and openssl_decode to Go?
There is such an implementation in php:
<?php
$token = 'c01d7c2768ba633990d458a78e0e4ce50627c20cffe54c8c';
$key = 'j0klBHYlVQOkc1LCE6ECZwBf1Siyvt5l';
$result = openssl_decrypt(hex2bin($token), 'BF-ECB', $key, OPENSSL_RAW_DATA | OPENSSL_NO_PADDING);
print_r($result);
// результат: {"t":1,"u":"1341/957"}
?>
Answer the question
In order to leave comments, you need to log in
package main
import (
"encoding/hex"
"fmt"
"golang.org/x/crypto/blowfish"
)
func main() {
encryptedText, _ := hex.DecodeString("c01d7c2768ba633990d458a78e0e4ce50627c20cffe54c8c")
key := []byte("j0klBHYlVQOkc1LCE6ECZwBf1Siyvt5l")
cipher, _ := blowfish.NewCipher(key)
plainText := make([]byte, len(encryptedText))
size := blowfish.BlockSize
for bs, be := 0, size; bs < len(encryptedText); bs, be = bs+size, be+size {
cipher.Decrypt(plainText[bs:be], encryptedText[bs:be])
}
fmt.Println(string(plainText))
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question