cryptography - Apex编码签名

  显示原文与译文双语对照的内容
0 0

我正在尝试在Apex中编写下面的VB函数:


Private Shared Function sign(ByVal data As String, ByVal secretKey As String) As String

 Dim encoder As New System.Text.UTF8Encoding
 Dim key() As Byte = encoder.GetBytes(secretKey)
 Dim dataAsBytes() As Byte = encoder.GetBytes(data)

 Dim myHMACSHA256 As New System.Security.Cryptography.HMACSHA256(key)
 Dim HashCode As Byte() = myHMACSHA256.ComputeHash(dataAsBytes)

 Return Convert.ToBase64String(HashCode)

End Function

谁能帮我?

时间: 原作者:

0 0

这是你创建签名的方式:


 String policy = '{"expiration":"' + expires + '",' + 
 '"conditions":[';
 List<String> clauses = new List<String>{};
 for(List<String> clause : conditions){
 clauses.add(genCondition(clause));
 }
 String conditionsString = String.join(clauses,',');
 policy += conditionsString;
 policy += ']}'; 
 policy = EncodingUtil.base64Encode(Blob.valueOf(policy)); 


signature = EncodingUtil.base64Encode(Crypto.generateMac('hmacSHA1', Blob.valueOf(base64EncodedPolicy), Blob.valueOf(Secret))); 

原作者:
...