首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >求告知OCR一直返回{"code":14,"message":"sign no pass"}原因?

求告知OCR一直返回{"code":14,"message":"sign no pass"}原因?

提问于 2019-01-15 16:58:02
回答 2关注 0查看 646

是什么问题导致的,想问下如何解决?

签名算法如下:

private static final String bucketName = "";

private static final long expired = 2592000;

/**

* 生成 Authorization 签名字段

*

* @param appId

* @param secretId

* @param secretKey

* @param bucketName

* @param expired

* @return

* @throws Exception

*/

public static String appSign(long appId, String secretId, String secretKey, String bucketName, long expired)

throws Exception {

System.out.println(expired);

long now = System.currentTimeMillis() / 1000;

int rdm = Math.abs(new Random().nextInt());

String plainText = String.format("a=%d&b=%s&k=%s&t=%d&e=%d&r=%d", appId, bucketName, secretId, now,

now + expired, rdm);

byte[] hmacDigest = HmacSha1(plainText, secretKey);

byte[] signContent = new byte[hmacDigest.length + plainText.getBytes().length];

System.arraycopy(hmacDigest, 0, signContent, 0, hmacDigest.length);

System.arraycopy(plainText.getBytes(), 0, signContent, hmacDigest.length, plainText.getBytes().length);

return Base64Encode(signContent);

}

/**

* 生成 base64 编码

*

* @param binaryData

* @return

*/

public static String Base64Encode(byte[] binaryData) {

String encodedstr = null;

try {

System.out.println(binaryData);

encodedstr = Base64.getEncoder().encodeToString(binaryData);

System.out.println(encodedstr);

} catch (Exception e) {

e.printStackTrace();

}

return encodedstr;

}

/**

* 生成 hmacsha1 签名

*

* @param binaryData

* @param key

* @return

* @throws Exception

*/

public static byte[] HmacSha1(byte[] binaryData, String key) throws Exception {

Mac mac = Mac.getInstance("HmacSHA1");

SecretKeySpec secretKey = new SecretKeySpec(key.getBytes(), "HmacSHA1");

mac.init(secretKey);

byte[] HmacSha1Digest = mac.doFinal(binaryData);

return HmacSha1Digest;

}

/**

* 生成 hmacsha1 签名

*

* @param plainText

* @param key

* @return

* @throws Exception

*/

public static byte[] HmacSha1(String plainText, String key) throws Exception {

return HmacSha1(plainText.getBytes(), key);

}

相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档