Search code examples
ruby-on-railsyodlee

Yodlee API return error with data encrypted


I'm building an app using yodlee and rails, everything works fine on sandbox, the problem it's when I use the live env, with the PKI feature.

I'm getting my API key from here

Then I'm using these lines of code to encrypt the sensitive information (username/password/pin)

  key= public_key
  rsa_key = OpenSSL::PKey::RSA.new(key.keyAsPemString)
  key.keyAlias + ":" +Base64.encode64(rsa_key.public_encrypt(value_to_encrypt))

I send the request but I'm getting this

 {"errorCode"=>"Y400", "errorMessage"=>"Decryption failure for FieldInfo:FieldInfoSingle: {FieldInfo: name=\"LOGIN\" displayName=\"null\" editable=true optional=false helpText=\"null\" valuePattern=\"null\" } defaultValue=\"null\" value=\"\" validValues=[null] displayValidValues=[null] valueIdentifier=\"null\" valueMask=\"null\" fieldType=\"TEXT\" validationRules=[null] size=null maxlength=null userProfileMappingExpression=null fieldErrorCode=null fieldErrorMessage=null ", "referenceCode"=>"RB_3cf12f35-05d3-4d87-a1f9-edcfc62df3d2"}

Any ideas?


Solution

  • The only difference from the official Java version of the encryption code seems to be the final encoding. It should be hex-encoded, not Base64-encoded. Try this instead:

    key.keyAlias + ":" + Digest.hexencode(rsa_key.public_encrypt(value_to_encrypt))