Sign text in C# with SHA256
up vote
0
down vote
favorite
I have some code in nodejs and I am trying to replicate in in C# but I can't seem to find a simple solution like the nodejs one:
var crypto = require('crypto');
var privateKey = '-----BEGIN RSA PRIVATE KEY-----n'+
/// key removed
'-----END RSA PRIVATE KEY-----';
var publicKey = '-----BEGIN PUBLIC KEY-----n'+
/// key removed
'-----END PUBLIC KEY-----';
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
console.log(sign);
// verify signature
var verifier = crypto.createVerify('sha256');
verifier.update('ugus-dev/logo.png');
var ver = verifier.verify(publicKey, sign,'base64');
console.log(ver); // true if signature matches.
Basically i will be singing a string in C# and then verifying the signature of the string in nodeJS with the obove code for verify.
So I am looking for an equvalent of:
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
in C#.
c# node.js cryptography sign
add a comment |
up vote
0
down vote
favorite
I have some code in nodejs and I am trying to replicate in in C# but I can't seem to find a simple solution like the nodejs one:
var crypto = require('crypto');
var privateKey = '-----BEGIN RSA PRIVATE KEY-----n'+
/// key removed
'-----END RSA PRIVATE KEY-----';
var publicKey = '-----BEGIN PUBLIC KEY-----n'+
/// key removed
'-----END PUBLIC KEY-----';
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
console.log(sign);
// verify signature
var verifier = crypto.createVerify('sha256');
verifier.update('ugus-dev/logo.png');
var ver = verifier.verify(publicKey, sign,'base64');
console.log(ver); // true if signature matches.
Basically i will be singing a string in C# and then verifying the signature of the string in nodeJS with the obove code for verify.
So I am looking for an equvalent of:
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
in C#.
c# node.js cryptography sign
stackoverflow.com/questions/14644926/…
– bartonjs
Nov 9 at 15:46
this did it for me, specifically the answer from Chris.J, Thanks bartonjs!
– Chester0
Nov 12 at 3:41
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have some code in nodejs and I am trying to replicate in in C# but I can't seem to find a simple solution like the nodejs one:
var crypto = require('crypto');
var privateKey = '-----BEGIN RSA PRIVATE KEY-----n'+
/// key removed
'-----END RSA PRIVATE KEY-----';
var publicKey = '-----BEGIN PUBLIC KEY-----n'+
/// key removed
'-----END PUBLIC KEY-----';
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
console.log(sign);
// verify signature
var verifier = crypto.createVerify('sha256');
verifier.update('ugus-dev/logo.png');
var ver = verifier.verify(publicKey, sign,'base64');
console.log(ver); // true if signature matches.
Basically i will be singing a string in C# and then verifying the signature of the string in nodeJS with the obove code for verify.
So I am looking for an equvalent of:
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
in C#.
c# node.js cryptography sign
I have some code in nodejs and I am trying to replicate in in C# but I can't seem to find a simple solution like the nodejs one:
var crypto = require('crypto');
var privateKey = '-----BEGIN RSA PRIVATE KEY-----n'+
/// key removed
'-----END RSA PRIVATE KEY-----';
var publicKey = '-----BEGIN PUBLIC KEY-----n'+
/// key removed
'-----END PUBLIC KEY-----';
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
console.log(sign);
// verify signature
var verifier = crypto.createVerify('sha256');
verifier.update('ugus-dev/logo.png');
var ver = verifier.verify(publicKey, sign,'base64');
console.log(ver); // true if signature matches.
Basically i will be singing a string in C# and then verifying the signature of the string in nodeJS with the obove code for verify.
So I am looking for an equvalent of:
// sign string
var signer = crypto.createSign('sha256');
signer.update('ugus-dev/logo.png');
var sign = signer.sign(privateKey,'base64');
in C#.
c# node.js cryptography sign
c# node.js cryptography sign
asked Nov 9 at 4:30
Chester0
134
134
stackoverflow.com/questions/14644926/…
– bartonjs
Nov 9 at 15:46
this did it for me, specifically the answer from Chris.J, Thanks bartonjs!
– Chester0
Nov 12 at 3:41
add a comment |
stackoverflow.com/questions/14644926/…
– bartonjs
Nov 9 at 15:46
this did it for me, specifically the answer from Chris.J, Thanks bartonjs!
– Chester0
Nov 12 at 3:41
stackoverflow.com/questions/14644926/…
– bartonjs
Nov 9 at 15:46
stackoverflow.com/questions/14644926/…
– bartonjs
Nov 9 at 15:46
this did it for me, specifically the answer from Chris.J, Thanks bartonjs!
– Chester0
Nov 12 at 3:41
this did it for me, specifically the answer from Chris.J, Thanks bartonjs!
– Chester0
Nov 12 at 3:41
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
A head start:
using System.Security.Cryptography;
using System.Text;
SHA256 mySHA=SHA256.Create();
string myText="yourText";
byte byteArr=Encoding.UTF8.GetBytes(myText);
byte hash=mySHA.ComputeHash(byteArr);
string res=BitConverter.ToString(hash);
//Or
string res=Convert.ToBase64String(hash);
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
This should help you.link
– bolkay
Nov 9 at 6:17
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
A head start:
using System.Security.Cryptography;
using System.Text;
SHA256 mySHA=SHA256.Create();
string myText="yourText";
byte byteArr=Encoding.UTF8.GetBytes(myText);
byte hash=mySHA.ComputeHash(byteArr);
string res=BitConverter.ToString(hash);
//Or
string res=Convert.ToBase64String(hash);
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
This should help you.link
– bolkay
Nov 9 at 6:17
add a comment |
up vote
0
down vote
A head start:
using System.Security.Cryptography;
using System.Text;
SHA256 mySHA=SHA256.Create();
string myText="yourText";
byte byteArr=Encoding.UTF8.GetBytes(myText);
byte hash=mySHA.ComputeHash(byteArr);
string res=BitConverter.ToString(hash);
//Or
string res=Convert.ToBase64String(hash);
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
This should help you.link
– bolkay
Nov 9 at 6:17
add a comment |
up vote
0
down vote
up vote
0
down vote
A head start:
using System.Security.Cryptography;
using System.Text;
SHA256 mySHA=SHA256.Create();
string myText="yourText";
byte byteArr=Encoding.UTF8.GetBytes(myText);
byte hash=mySHA.ComputeHash(byteArr);
string res=BitConverter.ToString(hash);
//Or
string res=Convert.ToBase64String(hash);
A head start:
using System.Security.Cryptography;
using System.Text;
SHA256 mySHA=SHA256.Create();
string myText="yourText";
byte byteArr=Encoding.UTF8.GetBytes(myText);
byte hash=mySHA.ComputeHash(byteArr);
string res=BitConverter.ToString(hash);
//Or
string res=Convert.ToBase64String(hash);
edited Nov 9 at 5:01
answered Nov 9 at 4:52
bolkay
4228
4228
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
This should help you.link
– bolkay
Nov 9 at 6:17
add a comment |
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
This should help you.link
– bolkay
Nov 9 at 6:17
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
how do I read my private key with this?
– Chester0
Nov 9 at 5:29
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
answering my own comment: mySHA.LoadPrivateFromXml(@"C:privateKey.xml"); mySHA.LoadPublicFromXml(@"C:publicKey.xml");
– Chester0
Nov 9 at 5:37
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
Good to know you've solved the problem.
– bolkay
Nov 9 at 5:39
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
I was wrong, : still not sure how to load the key
– Chester0
Nov 9 at 6:08
This should help you.link
– bolkay
Nov 9 at 6:17
This should help you.link
– bolkay
Nov 9 at 6:17
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219903%2fsign-text-in-c-sharp-with-sha256%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stackoverflow.com/questions/14644926/…
– bartonjs
Nov 9 at 15:46
this did it for me, specifically the answer from Chris.J, Thanks bartonjs!
– Chester0
Nov 12 at 3:41