This will not work with CNG(KSP)
Steps 1
1. When we create key/pair, store the KeyContainerName.
2. Sign CSR with created keys and get the certificate(one of CER/DER/PEM/CRT) format.
3. Open the certificate using x509certificate2 class, create CspParameter class. Assign the KeyContainerName to CspParamater class.
4. Create RsaCryptoProvider class using CspParamater, and assign it to PrivateKey of x509certificate2.
5. Using Export(pfx, password) option.
6. Clear RsaCryptoProvider using PersistCsp = false, and Clear().
Note
1. If you don't pass valid KeyContainerName, default will be created. But assigning to PrivateKey property will throw exception about Key mismatch(after all they are strongly related).
2. Clear the KeyContainer for better security purposes.
Sample code to get u started.
CspParameters p = new CspParameters();
p.ProviderName = "Microsoft Enhanced Cryptographic Provider v1.0";
p.ProviderType = 1;
p.KeyContainerName = "your container name";
p.KeyNumber = (int)AT_KEYEXCHANGE;
RSACryptoServiceProvider csp = new RSACryptoServiceProvider(p);
X509Certificate2 cer = new X509Certificate2("sss.cer");
cer.PrivateKey = csp;
byte[] bytes = cer.Export(X509ContentType.Pfx, "12345");
FileStream stream = new FileStream("CASigned.pfx", FileMode.CreateNew);
stream.Write(bytes, 0, bytes.Length);
stream.Close();
X509Certificate2 c1 = new X509Certificate2("CASigned.pfx", "12345");
bool value = c1.HasPrivateKey;
Thursday, 14 July 2011
Wednesday, 13 July 2011
Certificate file types
Two types of encoding used in certificate
1. DER(Distinguished Encoding Rule) - DER encoded certificate.
2. PEM - Base64 encoded certificate - starts with BEGIN CERTIFICATE and ends with END CERTIFICATE.
Above can also used and extensions.
Common extensions
-----------------
1. CRT - Most common among *nix systems
2. CER - alternate form of .CRT (Microsoft Convention)
The only time CRT and CER can safely be interchanged is when the encoding type can be identical. (ie PEM encoded CRT = PEM encoded CER)
1. DER(Distinguished Encoding Rule) - DER encoded certificate.
2. PEM - Base64 encoded certificate - starts with BEGIN CERTIFICATE and ends with END CERTIFICATE.
Above can also used and extensions.
Common extensions
-----------------
1. CRT - Most common among *nix systems
2. CER - alternate form of .CRT (Microsoft Convention)
The only time CRT and CER can safely be interchanged is when the encoding type can be identical. (ie PEM encoded CRT = PEM encoded CER)
Monday, 4 July 2011
Respecting windows UAC while using LsaOpenPolicy
Please use POLICY_VIEW_LOCAL_INFORMATION = 1;
so your code will become
LsaOpenPolicy(SystemName, ref LSA_OBJECT_ATTRIBUTES,
(int)POLICY_VIEW_LOCAL_INFORMATION, out IntPtr)
so your code will become
LsaOpenPolicy(SystemName, ref LSA_OBJECT_ATTRIBUTES,
(int)POLICY_VIEW_LOCAL_INFORMATION, out IntPtr)
Friday, 10 June 2011
Wix force install new msi
msiexec caches the installer, hence if you want to force executing new installer pls use
msiexec /fc installer.msi
This might be useful, because while developing you might have set installation conditions wrong, which might fire during un-installation as well, hence might block from doing so.
like
Above condition happens no matter what whether you are trying to install or uninstall.
msiexec /fc installer.msi
This might be useful, because while developing you might have set installation conditions wrong, which might fire during un-installation as well, hence might block from doing so.
like
Above condition happens no matter what whether you are trying to install or uninstall.
Thursday, 13 August 2009
PerCall - No Session - It is all confusing
http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/0739e712-2abe-4b10-8667-3de5c43e4552
Spring.Net - AutoProxy
AutoProxy is an important technique offered by Spring.Net. Read below forum discussion
http://forum.springframework.net/showthread.php?t=5655
http://forum.springframework.net/showthread.php?t=5655
AutoMapper
Disclaimer - I have been using AutoMapper only for two weeks, so i might be wrong here
So, This tool avoid lot of pain from writing mapping codes. But being said that it is not a mature tool and will be a pain in butt incase of even medium level hierarchies.
With the verion 0.3.1(from Code plex),
1. You can't use abstract relation ship - though r116(latest as of now) solves this problem. What i mean here is
If you map 'Dog' to 'Dog' with a code like .Map(new Source.Dog()), it fails.
But if Source.Animal is interface, then it works. What crap?
2. Not perfect with collections(r116)
But being said that, if you have classes with simple/no relationship, this is a great tool.
So, This tool avoid lot of pain from writing mapping codes. But being said that it is not a mature tool and will be a pain in butt incase of even medium level hierarchies.
With the verion 0.3.1(from Code plex),
1. You can't use abstract relation ship - though r116(latest as of now) solves this problem. What i mean here is
If you map 'Dog' to 'Dog' with a code like .Map
But if Source.Animal is interface, then it works. What crap?
2. Not perfect with collections(r116)
But being said that, if you have classes with simple/no relationship, this is a great tool.
Subscribe to:
Posts (Atom)