Created
August 18, 2016 13:45
-
-
Save cfj/6049d640f1a6654b94ee20343a6681e2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetOriginProof(int amount, string currency, string userToken) | |
{ | |
var uuid = Guid.NewGuid().ToString(); | |
JObject jsonObject = new JObject(); | |
jsonObject["amount"] = amount; | |
jsonObject["currency"] = currency; | |
jsonObject["user_token"] = userToken; | |
jsonObject["id"] = uuid; | |
var data = jsonObject.ToString(); | |
byte[] originalData = Encoding.UTF8.GetBytes(data); | |
RSACryptoServiceProvider RSAalg = new RSACryptoServiceProvider(); | |
RSAParameters Key = RSAalg.ExportParameters(true); | |
var signatureBytes = HashAndSignBytes(originalData, Key); | |
string signature = Convert.ToBase64String(signatureBytes); | |
JObject originProof = new JObject(); | |
originProof["data"] = data; | |
originProof["signature"] = signature; | |
var originProofString = originProof.ToString(); | |
return Convert.ToBase64String(Encoding.UTF8.GetBytes(originProofString)); | |
} | |
public static byte[] HashAndSignBytes(byte[] dataToSign, RSAParameters key) | |
{ | |
try | |
{ | |
RSACryptoServiceProvider rsAalg = new RSACryptoServiceProvider(); | |
rsAalg.ImportParameters(key); | |
return rsAalg.SignData(dataToSign, new SHA1CryptoServiceProvider()); | |
} | |
catch (CryptographicException e) | |
{ | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment