Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sending RSA-SH1 encoded requests? #54

Closed
rupert-git opened this issue Jul 12, 2017 · 3 comments
Closed

Sending RSA-SH1 encoded requests? #54

rupert-git opened this issue Jul 12, 2017 · 3 comments

Comments

@rupert-git
Copy link

Wondering if it's possible to use RSA-SH1 with this library. The example you've provided for request (Node.js) uses HMAC:

var oauth = OAuth({
    consumer: {
        key: 'xvz1evFS4wEEPTGEFPHBog',
        secret: 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw'
    },
    signature_method: 'HMAC-SHA1',
    hash_function: function(base_string, key) {
        return crypto.createHmac('sha1', key).update(base_string).digest('base64');
    }
});

To make it work with RSA, I've tried changing the OAuth.prototype.getSigningKey function to return an RSA private key, and used the following init:

var oauth = OAuth({
    consumer: {
        key: inputData.consumerKey,
        secret: inputData.consumerSecret
    },
    signature_method: 'RSA-SHA1',
    hash_function: function(base_string, key) {
      var buffer = new Buffer(base_string);
      var encrypted = crypto.privateEncrypt(key, buffer);
      return encrypted.toString("base64");
    }
});

But no luck so far. Just wondering if RSA is possible with this library's code - or am I barking up the wrong tree?

@ddo
Copy link
Owner

ddo commented Jul 13, 2017

@rupert-git seems like you doing at the right place. how about this:

const crypto = require('crypto');
const sign = crypto.createSign('RSA-SHA1');

hash_function: function(base_string, key) {
    sign.write(base_string);
    sign.end();
    return sign.sign(key, 'base64');
}

@rupert-git
Copy link
Author

Thanks @ddo, got an RSA-SH1 request working with your advice :)
Much appreciated!

@ddo
Copy link
Owner

ddo commented Jul 17, 2017

np

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants