Y
Y
ytaneu2022-01-12 00:42:46
PHP
ytaneu, 2022-01-12 00:42:46

how to write openssl_decrypt in golang?

actual php code:

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';
     }
   }


I tried like this, but something doesn't work, it gives scribbles, but you need 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
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question