Flex side
---------------------------------------------
import mx.utils.Base64Encoder;
import com.adobe.crypto.MD5;
import com.adobe.crypto.HMAC;
var hashed: String = HMAC.hash(secret, msg, MD5);
var encoder : Base64Encoder = new Base64Encoder();
encoder.insertNewLines=false;
encoder.encode(hashed);
return encoder.toString();
.Net WCF side
----------------------------------------------
private static string CreateSignature(string uri, string secret)
{
byte[] secretBytes = System.Text.UTF8Encoding.UTF8.GetBytes(secret);
System.Security.Cryptography.HMACMD5 hmac = new System.Security.Cryptography.HMACMD5(secretBytes);
byte[] dataBytes = System.Text.UTF8Encoding.UTF8.GetBytes(uri);
byte[] computedHash = hmac.ComputeHash(dataBytes);
//--------------------------------------------------
System.Text.StringBuilder sb = new System.Text.StringBuilder();
for (int i = 0; i < computedHash.Length; i++)
{
sb.Append(computedHash[i].ToString("x2")); // hex format
}
//-------------------------------------------------------
string encoded = Convert.ToBase64String(System.Text.UTF8Encoding.UTF8.GetBytes(sb.ToString()));
return encoded;
}
Cheers!
2 comments:
Thanks !
I am also working on some requirement to consume WCF Rest services from Flex.For which I am facing exactly same problem.I was not aware that in wcf side, after computing the hash,I need to convert to hex string.As you mentioned above hopefully this will solve my problem too.Thanks for sharing it here
electronic signature sharepoint
Post a Comment