@ytaneu

Как написать openssl_decrypt в golang?

собственно код php:

if(in_array('aes-256-cbc', openssl_get_cipher_methods())){
     if(openssl_decrypt(hex2bin($passHashArray[1]), 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv)){
        echo  'correct';
     }else{
        echo 'decrypt failed';
     }
   }


пытался вот так, но что-то не работает, выдает каракули, а нужно true/false :
result, err := decrypt(cipherTextDecoded, encKeyDecoded, ivDecoded)
	if err != nil {
		log.Printf("error hex decode string password hash array: %s", err)
	}
  log.Println(result)

func decrypt(cipherTextDecoded []byte, encKeyDecoded []byte, ivDecoded []byte) (string, error) {
	block, err := aes.NewCipher(encKeyDecoded)
	if err != nil {
		return "", err
	}

	mode := cipher.NewCBCDecrypter(block, ivDecoded)

	mode.CryptBlocks(cipherTextDecoded, cipherTextDecoded)

	return string(cipherTextDecoded), nil
}
  • Вопрос задан
  • 111 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы