如您所知,OAuth 可以支持 RSA-SHA1 签名。我有一个OAuthSignature
具有以下方法的界面
public String sign(String data, String consumerSecret, String tokenSecret) throws GeneralSecurityException;
我成功实现并测试了 HMAC-SHA1 签名(OAuth 支持)以及 PLAINTEXT“签名”。
我已经搜索了谷歌,如果我需要使用签名,我必须创建一个私钥SHA1withRSA
:示例代码:
/**
* Signs the data with the given key and the provided algorithm.
*/
private static byte[] sign(PrivateKey key,
String data)
throws GeneralSecurityException {
Signature signature = Signature.getInstance("SHA1withRSA");
signature.initSign(key);
signature.update(data.getBytes());
return signature.sign();
}
现在,我如何获取 OAuth 密钥(即 key = consumerSecret&tokenSecret)并创建一个PrivateKey
与SHA1withRSA
签名一起使用的密钥?
谢谢
来自OAuth 核心
9.3. RSA-SHA1
RSA-SHA1 签名方法使用 [RFC3447] 中定义的 RSASSA-PKCS1-v1_5 签名算法(Jonsson, J. 和 B. Kaliski,“Public-Key Cryptography Standards (PKCS) #1: RSA Cryptography; Specifications Version 2.1, ” .) 第 8.2 节(更简单地称为 PKCS#1),使用 SHA-1 作为 EMSA-PKCS1-v1_5 的哈希函数。假设消费者已经以一种经过验证的方式向服务提供者提供了它的 RSA 公钥,这种方式超出了本规范的范围。
我现在使用这个(http://code.google.com/apis/gdata/docs/auth/oauth.html)作为做 RSA-SHA1 签名的参考。