Unable to decrypt/decode key

2019-06-06 20:58发布

问题:

It appears that my consumer secret key for Twitter API 1.1 is not being decrypted in my CodeIgniter controller on my Amazon EC2 instance (slightly similar to this question) because

  • I got an unable to authenticate you error while troubleshooting
  • and my print_r($settings) statement (see below) displays unreadeable characters for the consumer secret in the browser inspite of the fact that I decrypted it with this line 'consumer_secret' => $this->encrypt->decode($this->config->item('consumer_secret').

my_controller.php

$settings = array(
            'oauth_access_token' => $this->config->item('oauth_access_token'),
            'oauth_access_token_secret' => $this->config->item('oauth_access_token_secret'),
            'consumer_key' => $this->config->item('consumer_key'),
            'consumer_secret' => $this->encrypt->decode($this->config->item('consumer_secret'))
        );  
        print_r($settings);

Note: I saved the encrypted consumer secret key in CodeIgniter's configuration directory and also set my encryption key in config.php. Interestingly, it works fine in WAMP but not in Amazon EC2.

How do I resolve this problem? Should I just save the unencrypted consumer secret key in the configuration file?

回答1:

Codeigniter uses some standard encryption libraries and falls back if they aren't available. I don't think mcrypt is available on the default Amazon Linux AMI. You can

a) use the fallback; just re-encrypt the consumer_secret on ec2 and put it in the config

b) install mcrypt

$ sudo yum install php-mcrypt
$ sudo service httpd restart