Skip to content

Instantly share code, notes, and snippets.

@pomarc
Created July 31, 2014 07:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pomarc/670a22e294c45e10f36e to your computer and use it in GitHub Desktop.
Save pomarc/670a22e294c45e10f36e to your computer and use it in GitHub Desktop.
static byte[] Sign(string message, byte[] secretKey)
{
byte[] messageBuffer = UTF8Encoding.UTF8.GetBytes(message);
var signedMessage = new byte[CryptoSign.Bytes + messageBuffer.Length];
int smlen;
CryptoSign.Sign(signedMessage, 0, out smlen, messageBuffer, 0, messageBuffer.Length, secretKey);
if (smlen != signedMessage.Length)
{
var buffer = new byte[smlen];
Array.Copy(signedMessage, 0, buffer, 0, smlen);
return buffer;
}
else
{
return signedMessage;
}
}
static string Verify(byte[] signedMessage, byte[] publicKey)
{
var buffer = new byte[signedMessage.Length];
int mlen;
if (CryptoSign.Open(buffer, 0, out mlen, signedMessage, 0, signedMessage.Length, publicKey)
!= 0)
{
throw new ArgumentException("Could not verify message!");
}
char[] messageBuffer = UTF8Encoding.UTF8.GetChars(buffer, 0, mlen);
return new string(messageBuffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment