We have two files, one is plain text another is signature file. We have to verify the integrity of the message.
The details of SIG file is as under:
Digital signature in PKCS7 format
Signatures are attached in detach mode
Algorithm : SHA1
Signature rule: End certificate of the User. .
What we are doing is
1. Calculating the hash of plain text file say it is hasPlain
2. Extracting the public key from SIG file
3. Extracting the Encrypted Hash from SIG file
4. Decrypting the above hash by using public key say it will give us hashSign
5. Comparing hashPlain and hasSign, if both are equal then signature is verified
6. We are using RSACryptoserviceprovider class of .net
We are able to extract the public key from SIG file but we are not able to extract Encrypted Hash from SIG File.
Please help
3 3587
So what have you tried so far?
- X509Certificate2 x509_2 = new X509Certificate2("c:\\EP00000100008052201.sig")
-
byte[] cer_data = x509_2.PublicKey.Key
-
-
FileStream fsw = new FileStream("C:\\cc.cer", FileMode.OpenOrCreate, FileAccess.Write);
-
fsw.Write(cer_data, 0, cer_data.Length);
-
fsw.Close();
-
// certificate has been generated
-
-
FileStream fs1 = new FileStream("c:\\EP00000100008052201.sig", FileMode.Open, FileAccess.Read);
-
byte[] tot_bytes = new byte[fs1.Length];
-
fs1.Read(tot_bytes, 0, tot_bytes.Length);
-
fs1.Close();
-
fsw = new FileStream("C:\\left.sig", FileMode.OpenOrCreate,FileAccess.Write);
-
-
string shouldIWrite;
-
int tot = 0;
-
for (int i = 0; i < tot_bytes.Length; i++)
-
{
-
shouldIWrite = "Y";
-
for (int j = 0; j < cer_data.Length; j++)
-
{
-
if (tot_bytes[i] == cer_data[j])
-
shouldIWrite = "N";
-
}
-
if (shouldIWrite == "Y")
-
{
-
tot++;
-
fsw.WriteByte(tot_bytes[i]);
-
}
-
}
-
fsw.Close();
-
-
-
FileStream fs = new FileStream("c:\\EP00000100008052201.txt", FileMode.Open, FileAccess.Read);
-
byte[] plainbyte = new byte[fs.Length];
-
fs.Read(plainbyte, 0, plainbyte.Length);
-
SHA1 sha = new SHA1CryptoServiceProvider();
-
byte[] plain_hash = sha.ComputeHash(plainbyte);
-
fs.Close();
-
-
fs = new FileStream("C:\\left.sig", FileMode.Open, FileAccess.Read);
-
byte[] leftout_bytes = new byte[fs.Length];
-
fs.Read(leftout_bytes, 0, leftout_bytes.Length);
-
fs.Close();
-
-
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
-
rsa.FromXmlString(x509_2.PublicKey.Key.ToXmlString(false));
-
-
byte[] encrypted_data = rsa.Decrypt(leftout_bytes,true);
-
-
// here we are facing the problem
-
// once we will decrypt it we can get the hash and then compare with the hash of plain file calculated earlier
-
-
-
if (plainbyte == encrypted_data)
-
MessageBox.Show("Y");
-
else
-
MessageBox.Show("N");
-
Have you manually checked that the decryption is working properly?
Are you sure that you are reading leftout_bytes contains all of the bytes required for the decryption to work correctly?
-Frinny
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Kim H Madsen |
last post by:
I have created a .Net Service that is sending mails using SMTP Server/Exchange Server how do i put in a Digital Signature so the reciver is 100% sure that the mail i from the owner of Server where...
|
by: CLarkou |
last post by:
I bought a digital signature for my MSaccess application in Office
2003. I select TOOLS\Digital Signatures in Visual Basic Editor and I
am not able to see my digital signature in the available...
|
by: Xavier |
last post by:
hello,
i have a kind of workflow like:
enter data in a form
aprove data by person 1
aprove data by person 2
data are saved in a sqldatabase
|
by: Geagleeye |
last post by:
Hi everyone.
I have some vba code to generate a pdf document through word, and add
also digital signature.
My problem is : how can i change the way the signature layout, it
always show the...
|
by: Ralph.Malek |
last post by:
Would anyone happen to know how to determine if a digital signature
used MD5 or SHA1 as the digest algorithm?
I have a requirement to verify the authenticity of VeriSigned exe
file, and while...
|
by: sudankanakavel |
last post by:
i need a software which implement digital signature using
algorithm:rsa,elgamal
language:java
os:windows
software should compress,encrypt and sign data.
decryption,certificate...
|
by: =?Utf-8?B?S29saW4=?= |
last post by:
Hi There,
I am a newbe to web services and WSE 3.0. I am connecting to a remote web
service using Web Proxy and the remote service required the soap message to
be digitaly signed(X509...
|
by: itcoll |
last post by:
i have wriiten java code for client server communication - the client sends a digital signature and the server verifies it using the public key .I have sent the signature as a string from the client...
|
by: tmoloy |
last post by:
I am using RFID tags to store some data which will then be read by a 3rd party. I need to include a digital signature (or some variation) along with the data so that the 3rd party can verify the...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |