[Progress Communities] [Progress OpenEdge ABL] Forum Post: Encryption - HMAC

Status
Not open for further replies.
G

goo

Guest
11.7 I am trying to do a test to replicate the jwt.io using Progress, This example: I am following this example : HMAC Example C#/.NET The code seems pretty simple, and this is what I did: define variable oLogin as class oo.DataHelper.LoginHelper no-undo. define variable oAuth as class oo.DataHelper.Auth2 no-undo. define variable oHeader as class Progress.Json.ObjectModel.JsonObject no-undo. define variable oPayload as class Progress.Json.ObjectModel.JsonObject no-undo. define variable EncodedPayload as character no-undo. define variable EncodedHeader as character no-undo. //oLogin = new oo.DataHelper.LoginHelper(). oAuth = new oo.DataHelper.Auth2(). //oParser = new Progress.Json.ObjectModel.ObjectModelParser(). oHeader = new Progress.Json.ObjectModel.JsonObject(). oPayload = new Progress.Json.ObjectModel.JsonObject(). oHeader:Add('alg','HS256'). oHeader:Add('typ','JWT'). oPayload:Add('sub','1234567890'). oPayload:Add('name','John Doe'). oPayload:Add('iat', 1516239022). EncodedHeader = string(oAuth:EncodeObject(oHeader)). EncodedPayload = string(oAuth:EncodeObject(oPayload)). MESSAGE EncodedHeader '.' EncodedPayload VIEW-AS ALERT-BOX. MESSAGE string(oAuth:DecodedText(EncodedHeader):GetJsonText()) skip string(oAuth:DecodedText(EncodedPayload):GetJsonText()) VIEW-AS ALERT-BOX. MESSAGE string(oAuth:HMACSHA256('test',EncodedHeader + '.' + EncodedPayload)) VIEW-AS ALERT-BOX. /**oAuth2.cls**/ METHOD PUBLIC LONGCHAR HMACSHA256( INPUT ipKeyString AS CHAR, INPUT ipEncodedString AS CHARACTER): /*------------------------------------------------------------------------------ Purpose: Notes: ------------------------------------------------------------------------------*/ DEFINE VARIABLE ByteArray AS "System.Byte[]" NO-UNDO. DEFINE VARIABLE KeyArray AS "System.Byte[]" NO-UNDO. DEFINE VARIABLE HMACByteArray AS "System.Byte[]" NO-UNDO. DEFINE VARIABLE oHMACSHA256 AS CLASS System.Security.Cryptography.HMACSHA256 NO-UNDO. ByteArray = System.Text.ASCIIEncoding:ASCII:GetBytes(ipEncodedString). KeyArray = System.Text.ASCIIEncoding:ASCII:GetBytes(ipKeyString). oHMACSHA256 = NEW System.Security.Cryptography.HMACSHA256(KeyArray). HMACByteArray = oHMACSHA256:ComputeHash(ByteArray). // RETURN System.Text.ASCIIEncoding:ASCII:GetString(HMACByteArray). I need to do something like this in C#: this.hmac2.Text = ByteToString(hashmessage); } public static string ByteToString(byte [] buff) { string sbinary=""; for (int i=0;i<buff.Length;i++) { sbinary+=buff.ToString("X2"); // hex format } return(sbinary); } But I am kind of lost here END METHOD.

Continue reading...
 
Status
Not open for further replies.
Top