Hello my goal is it to encrypt the password of a zipfile. As for now I only had to generate a SHA Hash
which will be my password and used the RSA-Cryptoprovider
with me private key to encrypt the password.
Now I need to use .p7b
and .p12
certificates to do this task.
But I dont understand what do I need those files for after some research I figured out that .p12
will be probably the file that I use to encrypt my password but what do I need .p7b
for?
That is what I did so far with it, it seems to work because I can read the string but still what do I need my .p7b
file for?
var password = @"test";
var p12FilePath = @"key\Test.p12";
var text = @"myFutureZipPassword";
X509Certificate2 cert = new X509Certificate2(p12FilePath, password, X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
byte[] certData = cert.Export(X509ContentType.Pfx, password);
RSACryptoServiceProvider rsaKey = (RSACryptoServiceProvider)cert.PrivateKey;
SHA1Managed sha1 = new SHA1Managed();
UnicodeEncoding encoding = new UnicodeEncoding();
byte[] data = encoding.GetBytes(text);
byte[] hash = sha1.ComputeHash(data);
var sign = rsaKey.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
var str = System.Text.Encoding.Default.GetString(sign);