【发布时间】:2011-02-02 10:56:44
【问题描述】:
如您所知,OAuth 可以支持 RSA-SHA1 签名。我有一个OAuthSignature 接口,它有以下方法
public String sign(String data, String consumerSecret, String tokenSecret) throws GeneralSecurityException;
我成功实现并测试了 HMAC-SHA1 签名(OAuth 支持)以及 PLAINTEXT“签名”。
我已经在google上搜索过,如果需要使用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 签名一起使用?
谢谢
9.3。 RSA-SHA1
RSA-SHA1 签名方法使用 RSASSA-PKCS1-v1_5 签名算法 如 [RFC3447] (Jonsson, J. 和 B. Kaliski,“公钥 密码学标准 (PKCS) #1:RSA 密码学;规格版本 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 签名的参考。
【问题讨论】:
标签: java oauth digital-signature