using System.Security.Cryptography;
public static void Main()
string serviceUrl = "https://api-gateway.walmart.com/v3/items?limit=200&nextCursor=*&shipNode=64103";
string clientId ="b606771d-ced6-4553-9356-a8a920827d03";
string clientSecret ="MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAO3H7a40BjHkGabSRHXw/8SJPyOK2FAEvvsN6ih6O4ARVhJe7iDFRF/i3uszON90JucUT5zFKqjQsSq46mC14tS8RBAFfiTsK4rSCogjnDZC1xY0HsF2GE4ajprFWVpE2y1aP4Vf83nyw6ab9MeVabo6P9YOzyUR13WaV4svnFcbAgMBAAECgYEAuwAx/3+wo4oFVnolFzBKpfFeM4CdcAjbfavKzLyckLKRo27/Dcy2YkaVFBo7jxjVA4Sou90gGJXPz46P3TEOSsYWPPsFeaBJ1Y3GFCHLARRST6zgIYOX9sQcYC+i0QX/5LG93J6Ftljp/VhKGig76etCnE//5GTzqbKPKx3sQEECQQD3p27c0r3Jsxe/hE1+k4gdbOs5RQ5ioSc7MDRy3SklKXH4jqV8U9gBqiCmA951EBnmu7EJJw1K+73reMSwFGO7AkEA9ctRd+O/1cdrWcqhBgCdV2joA9OaaWQJj/eEtviKWHJbB7elzJNOKqeZyYoffNVzaNYn0gZDguQCUJ5dsNS0IQJAPjrgbLS34/sQuJsyLeA8j8hSwy1LFBWSmhje1Q4lzKTBcsfFZZxb5u8tDQpj196X45a+QaKCgJkJfCX4ppY5CQJAGNbeOc5zUYhgqedXVIL1Y6L/Z3uX7DSm3ry11cPSP1P3LRV7FOyCBr9/RCXIPtZXXm3eAlSNuAmQzlLixv8H4QJBAMeqGp4yTE9VmvUCxsEMYGI2ezSfxhlt8WOx0V6H4EyHxNDCKasP6rIvuKTUFKCjLHNpGnVcsV5NfMxriqPDvZg=";
DateTime UtcNow = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
long timeStampVal = (long)(DateTime.UtcNow - UtcNow).TotalMilliseconds;
StringBuilder sbStringToSign = new StringBuilder();
sbStringToSign.Append(clientId);
sbStringToSign.Append("\n");
sbStringToSign.Append(serviceUrl);
sbStringToSign.Append("\n");
sbStringToSign.Append("GET");
sbStringToSign.Append("\n");
sbStringToSign.Append(timeStampVal);
sbStringToSign.Append("\n");
String signature = GenerateSignature(sbStringToSign.ToString(), clientSecret);
Console.WriteLine("Signature : "+ signature);
Console.WriteLine("timestamp : "+ timeStampVal);
public static string GenerateSignature(
string signatureString = null;
byte[] privateKey = Convert.FromBase64String(encodedPrivateKey);
RSACryptoServiceProvider rsa = DecodePrivateKeyInfo(privateKey);
byte[] CO = Encoding.UTF8.GetBytes(stringToBeSigned);
byte[] SignedBytes = rsa.SignData(CO, CryptoConfig.MapNameToOID("SHA256"));
signatureString = Convert.ToBase64String(SignedBytes);
public static RSACryptoServiceProvider DecodePrivateKeyInfo(
byte[] SeqOID = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
MemoryStream mem = new MemoryStream(pkcs8);
int lenstream = (int)mem.Length;
BinaryReader binr = new BinaryReader(mem);
twobytes = binr.ReadUInt16();
else if (twobytes == 0x8230)
twobytes = binr.ReadUInt16();
seq = binr.ReadBytes(15);
if (!CompareBytearrays(seq, SeqOID))
byte[] rsaprivkey = binr.ReadBytes((int)(lenstream - mem.Position));
RSACryptoServiceProvider rsacsp = DecodeRSAPrivateKey(rsaprivkey);
private static bool CompareBytearrays(
if (a.Length != b.Length)
public static RSACryptoServiceProvider DecodeRSAPrivateKey(
byte[] MODULUS, E, D, P, Q, DP, DQ, IQ;
MemoryStream mem = new MemoryStream(privkey);
BinaryReader binr = new BinaryReader(mem);
twobytes = binr.ReadUInt16();
else if (twobytes == 0x8230)
twobytes = binr.ReadUInt16();
elems = GetIntegerSize(binr);
MODULUS = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
E = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
D = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
P = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
Q = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
DP = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
DQ = binr.ReadBytes(elems);
elems = GetIntegerSize(binr);
IQ = binr.ReadBytes(elems);
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAparams = new RSAParameters();
RSAparams.Modulus = MODULUS;
RSA.ImportParameters(RSAparams);
private static int GetIntegerSize(
highbyte = binr.ReadByte();
lowbyte = binr.ReadByte();
byte[] modint = { lowbyte, highbyte, 0x00, 0x00 };
count = BitConverter.ToInt32(modint, 0);
while (binr.ReadByte() == 0x00)
binr.BaseStream.Seek(-1, SeekOrigin.Current);