Avatar of Camillia
Camillia
Flag for United States of America asked on

Convert this one line of Java code to C#

I'm following an example in this link:

https://firstdata.zendesk.com/entries/452518-generating-the-payment-request-form-programmatically

1. I know I need to use .Net's cryptography class.
2. If you look at the example, I need to convert these lines to C#. Any ideas?

// Use Java Cryptography functions to generate the x_fp_hash value
// generate secret key for HMAC-SHA1 using the transaction
 keySecretKey key = new SecretKeySpec(transactionKey.getBytes(), "HmacSHA1");

Open in new window


and

// Get instance of Mac object implementing HMAC-SHA1, and
// Initialize it with the above secret key
Mac mac = Mac.getInstance("HmacSHA1");mac.init(key);

Open in new window

C#ASP.NET

Avatar of undefined
Last Comment
Camillia

8/22/2022 - Mon
Randy Downs

Try this
http://www.codeproject.com/Articles/10154/NET-Encryption-Simplified

Dim sym As New Encryption.Symmetric(Encryption.Symmetric.Provider.TripleDES)
Dim key As New Encryption.Data("My Password")
Dim fs As New IO.FileStream("c:\test.txt", IO.FileMode.Open, 
                            IO.FileAccess.Read)
Dim br As New IO.BinaryReader(fs)
Dim encryptedData As Encryption.Data
encryptedData = sym.Encrypt(br.BaseStream, key)
br.Close()

Open in new window

Element1910

HMACSHA1 hmacsha1 = new HMACSHA1(transactionKey);

Open in new window


all you need to do for C# is pass the key into the new HMACSHA1 object you create.
Camillia

ASKER
thanks both of you, So I have : HMACSHA1 hmacsha1 = new HMACSHA1(transactionKey);

How about this line?

Mac mac = Mac.getInstance("HmacSHA1");mac.init(key);
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Element1910

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Camillia

ASKER
let me try, thanks