Security :: Encrypting With An X509 Certificate.

Mar 14, 2011

I have created an x590 certificate that is in the file :
"C:UsersmartinAppDataRoamingMicrosoftSystemCertificatesMyCertificates"

I am trying to acces the public key to encrypt some plain text.

The system is throwing an "System.ArgumentOutOfRangeException" at the line

Dim certificate As X509Certificate2 = certificateCollection(0)

Can anyone tell me where I am going wrong or tell me another way to access the public key

.................................................
This is the complete code:
Imports System.Security
Imports System.Security.Cryptography.X509Certificates
Imports System.Security.Cryptography.X509Certificates.X509Certificate2
Imports System.Security.Cryptography.Pkcs
Partial Class encryptwithcertificare
Inherits System.Web.UI.Page
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim encoding As UTF8Encoding = New UTF8Encoding
Dim cleartext As String = Textbox1.Text
Dim myStore As X509Store = New X509Store()
myStore.Open(OpenFlags.ReadOnly)
Dim certificateCollection As X509Certificate2Collection = myStore.Certificates.Find(X509FindType.FindBySubjectName, "bobby", True)
Dim certificate As X509Certificate2 = certificateCollection(0)
Dim code() As Byte = EncryptwithCertificate(cleartext, certificate)
Label1.Text = Convert.ToBase64String(code)
End Sub
Shared Function EncryptwithCertificate(ByVal cleartext As Byte, ByVal certificate As X509Certificate2) As Byte()
Dim encoding As UTF8Encoding = New UTF8Encoding
Dim cleartextsbyte() As Byte = encoding.GetBytes(cleartext)
Dim contentinfo As ContentInfo = New ContentInfo(cleartextsbyte)
Dim envelopedCms As EnvelopedCms = New EnvelopedCms(contentinfo)
Dim recipient As CmsRecipient = New CmsRecipient(certificate)
envelopedCms.Encrypt(recipient)
Return envelopedCms.Encode()
End Function
End Class

View 3 Replies


Similar Messages:

Security :: Using A X509 Certificate In A Web-service

Jun 17, 2010

I have a rather strange situation that I am in.

I have to write a web-service that will (among other things) communicate with another web service. When we communicate with that remote web-service we are required to use a certificate that they provided.

I am having a really hard time trying to find any sample code that does this.

I have found code for installing certs when you want to use a browser to communicate, but none when you are using a web-service to web-service and you are required to HAVE the certificate, not requiring the OTHER end to have the certificate.

So far I cannot even find code to allow me to parse throught the cert store. Samples I found online show up as errors in Visual Studio 2005.

Note: This is running one Windows 2000, designed with Visual Studio 2005, asp.net 2.0

View 1 Replies

Security :: Add CSP Information To X509 Certificate Programmatically

Mar 3, 2010

I'm working on a project for a large company that wants to create a crypto toolbox for cross-platform signing and encrypting and am constantly running into problems concerning the cryptographic abilities in the .Net framework. The blazing inferno that I need to put out this time is that SignedCms and EnvelopedCms don't seem to work with a Cryptographic Service Provider that doesn't store the private-key on the Windows machine. I'm working with a network HSM and certicates that have only a public key, that is, no private-key and no information in the store as to where that private-key resides or how you can access it (a RSA public/private key pair is created on the machine, using the HSM supplier's CSP, and a certificate signing request is generated and used to create a public-key certificate signed by the CA). Theoretically the private key gets picked up from the HSM (referenced actually) using the CspParameters given when instantiating the class, which specifies the CSP provided by the HSM supplier. Unfortunately, up to now this only works with CAPI, where can associate the cryptographic service provider with the signing certificate (usign CertSetCertificateContextProperty with CERT_KEY_PROV_HANDLE_PROP_ID). (We're using CAPI for PKCS#7 signing because the .Net framework only supports signatures up to SHA1 and we have a minimum of SHA256). Surprisingly enough CmsSigner accepts a CSP in it's constructor but it cannot get the key, it throws an exception during instantiation from method CreateDummyCertificate for some reason (with the message "Process completed." no less!??). I use the following CspParameters:

[Code]....

CmsSigner cmsSigner = new CmsSigner(cspParams);

This process works great with certificates and key pairs created by MakeCert. With MakeCert you can associate the CSP information with the Certificate upon creation (-sk, -sp, -sy). The private key still resides in the HSM but specifying the provider during the creation of the certificate seems to have persisted the CSP information somewhere, somehow. Exactly how that's done I don't know, but if could do that, my problem would be solved.

View 2 Replies

Security :: X509 - Client Certificate Infrastructure

Sep 9, 2010

I dont have a lot of background with SSL and X509 configuration and support with my Asp.Net application, so I was wondering if someone can explain or point me in the right direction to MSDN or any other article or posting explaining if it's possible to do what I am looking to support in my environment.

I have IIS 6.0 with SSL (Verisign cert) as well as "Require client certificates" working against a local installation of Microsoft Certificate Services, https://<domain>/certsrv, where users can request and install client certs (both xp clients for basic
mode, and Vista/7 for advance mode).

Here's what I am up against:

I have a segment of users coming from a virtualized server environment where this environment does not store personal settings for more than 48 hours. It's not an internet cafe, but rather an actual business where their IT staff uses server images to reimage each virtual server in the farm every 48hrs. Thus losing all users data in the "Current Users" Certificate Stores.

The IT staff give users a network folder share to store any personal items (docs, spreadsheets, links, etc.). The servers consist of Windows Server 2003, and will be migrating to Windows Server 2008 in the next 6-9 months.

These users have rights in Internet Explorer to navigate to my certsrv site and use activex to to request and install certificates then clode and reopen the broser to navigate and render the asp.net app.


Problem:

It's a pain to ask the users to request and have issued a client certificate every 48 hours.

The IT staff of this company has asked if I can create some sort of certificate that they can load in the "local computer" certificate store, NOT the "Current User" store, that will be made part of their base image for all their servers, and that this certificate is then used to properly authenticate all users on these servers to my IIS with "require client certificates" selected.

Question:

Is this possible, and if so what can I do on my side to create the proper certificate to give to the IT staff at this business to put into their servers "local computer" certificate store? I assume either under the Personal->Certificates store, or under the "Trusted Root Certification Authorities"->Certificates store. Thus allowing any user of these servers in their thin client virtual environment to open I.E., navigate to my site and select a certificate from the "Choose a digital certificate" popup that allows them to render my Asp.Net application, or avoids this popup altogether.

If this is the wrong forum to post in, please advise and I will move. Probably due to vernacular on my part, I have been unable to find any resources on here, MSDN or Bing to help me solve this problem.

View 1 Replies

WCF / ASMX :: Web Service Security Using X509 Certificate

Nov 17, 2010

Am facing problem while consuming a java web service using WCF. below is the web.config and aspx.cs file details

Requirement

Service request and response will be encrypted with certificate. when i run this below code am getting the error "The private key is not present in the X.509 certificate."

<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="TestClientCertificate">
<clientCredentials>
<clientCertificate storeLocation="CurrentUser" storeName="My"
findValue="certificatename" x509FindType="FindByIssuerName"/>
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TestHttpBinding" maxReceivedMessageSize="1048576" maxBufferSize="1048576" transferMode="Buffered">
<security mode="TransportWithMessageCredential">
<!--<transport clientCredentialType="Certificate"/>-->
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="TestHttpPort" address="https://webserviceurl/webservice"
binding="basicHttpBinding" bindingConfiguration="TestHttpBinding"
behaviorConfiguration="TestClientCertificate"
contract="ServiceReference1.webService1">
</endpoint>
</client>
</system.serviceModel>

in page
protected void Page_Load(object sender, EventArgs e)
{
WebServiceClient abc = new WebServiceClient();
BindingElementCollection elements = abc.Endpoint.Binding.CreateBindingElements();
elements.Find<SecurityBindingElement>().IncludeTimestamp = true;
abc.Endpoint.Binding = new CustomBinding(elements);
WebServiceClientResponse xyz = abc.WebMethod("", "");
}
private static bool customXertificateValidation(object sender, X509Certificate cert, X509Chain chain, System.Net.Security.SslPolicyErrors error)
{
return true;
}
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="TestClientCertificate">
<clientCredentials>
<clientCertificate storeLocation="CurrentUser" storeName="My"
findValue="partnerservices" x509FindType="FindByIssuerName"/>
</clientCredentials>
<!--<serviceDebug includeExceptionDetailInFaults="true"/>-->
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="TestHttpBinding" maxReceivedMessageSize="1048576" maxBufferSize="1048576" transferMode="Buffered">
<security mode="TransportWithMessageCredential">
<!--<transport clientCredentialType="Certificate"/>-->
<message clientCredentialType="Certificate"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint name="TestHttpPort" address="https://webservicespprd.biworldwide.com/partnerservices/services/v1/AccountWebService.biws"
binding="basicHttpBinding" bindingConfiguration="TestHttpBinding"
behaviorConfiguration="TestClientCertificate"
contract="ServiceReference1.AccountWebService">
<!--<identity>
<certificate encodedValue="MIIB5zCCAVCgAwIBAgIQlerVslZ+4p1Of3evhNc3TDANBgkqhkiG9w0BAQQFADAP
MQ0wCwYDVQQDEwRTR0JJMB4XDTEwMTExNjA5MjYyOVoXDTM5MTIzMTIzNTk1OVow
DzENMAsGA1UEAxMEU0dCSTCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA5mYW
n4Qp/8uosJ56fXLqygOkTDuYTTX0KECRce7fkeCFH8SpqQeCltNMjFgNRzr+C4rk
6A7GFe6gMiVyogqYgQn/QyZGT5iTXJ4khkAYui/gLX4Cga3tBCoVckja/93bCUOS
G4rS7W86kgG2hV+BfceqmlRISnlaLWxN/Ys6TAsCAwEAAaNEMEIwQAYDVR0BBDkw
N4AQ7veQWUUKR17/SJxFCEHu56ERMA8xDTALBgNVBAMTBFNHQkmCEJXq1bJWfuKd
Tn93r4TXN0wwDQYJKoZIhvcNAQEEBQADgYEAPsTiaYcghQCtBRH8FupLZIzliSHx
h3rsr6mKQT68rA+I9qjs/lsPaN2ebajDb3xzJRmjlrz2+9Gjc9LUGDaHEgxsPHab
Dh/IOgkqyjVAJHufjroKFfkzTJwwB4/uWU2vOKPpqVXfLqRXJ8du25MI7iWcHVfg
oYS1eESNBuPCErQ="/>
</identity>-->
</endpoint>
</client>
</system.serviceModel>

View 7 Replies

Security :: View A Current Users X509 Certificate Store

Mar 15, 2011

Quick question: is it possible to retrive a users certificate store i.e. list all of the client's Personal Certificates?

Just to be clear, I am talking about the certificates installed on the clients machine, not the servers. I have managed to list the server's certificates, but so far have been unsuccesful with the above.

View 2 Replies

C# - How Do I Find The Subjectdistinguishedname Of A X509 Certificate

Jul 12, 2010

I am trying to use the X509FindType.FindBySubjectDistinguishedName option and I am not sure where to find the value for the findValue property in my config.

http://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.x509findtype.aspx

View 1 Replies

C# - Can't Connect To HTTPS Using X509 Client Certificate

May 24, 2010

I'm new to cryptography and I'm a bit stuck:

I'm trying to connect (from my development environment) to a web service using HTTPS. The web service requires a client certificate - which I think I've installed correctly.

They have supplied me with a .PFX file. In Windows 7, I double clicked the file to install it into my Current User - Personal certificate store.

I then exported a X509 Base-64 encoded .cer file from the certificate entry in the store. It didn't have a private key associate with it.

Then, in my app, I'm attempting to connect to the service like this:

var certificate = X509Certificate.CreateFromCertFile("xyz.cer"));
var serviceUrl = "https://xyz";
var request = (HttpWebRequest) WebRequest.Create(serviceUrl);
request.ClientCertificates.Add(certificate);
request.Method = WebRequestMethods.Http.Post;
request.ContentType = "application/x-www-form-urlencoded";

I get a 502 Connection failed when I connect.

Is there anything you can see wrong with this method? Our production environment seems to work with a similar configuration, but it's running Windows Server 2003.

View 2 Replies

Security :: Decrypting Using X509 Certificates?

Mar 16, 2011

I am trying to decrypt using an X509 certificate private key. I am using the following function:

[Code]....

View 3 Replies

Security :: Request A Client's X509 Cert W/o Windows Auth

Mar 15, 2010

Is it possible to request an X509 certificate from a client without configuring the application to use Windows Authentication? The purpose would be to press an asp.net button and "digitially sign" a web-form's contents. I do not need any login information, just the X509 cert.

View 1 Replies

Security :: Password Encrypting?

Oct 12, 2010

I have been trying to encrypt password and found a code which is working with Access fine but as i have changed to SQL it is not decoding the encrypted text.. it amazes me..this SQl code is not letting me log on..

[Code]....

Whereas this OlebDB/Access is working fine

[Code]....

View 4 Replies

Security :: How To Implement Certificate Security In Production Environment

Jun 15, 2010

I have searched and could not find any article related to "How to implement Certificate Security in
production environment".

I could able to Create sample certificates for client and Server on my local machine and was able to authenticate my client app with the certificates . These certificates are test certificates.

How do I do this in Production. We have a domain certificate from GoDaddy which resides on the server. How do I create a Client Certificate off of that.

View 2 Replies

Security :: Encrypting Section In Web.config?

May 3, 2010

I am wondering how to encrypt the below information in the "web.config" file of the "Account" folder (where we have the secured pages):

[Code]....

My issue here is that even after I compiled my application (using "aspnet_compiler -v /reports c:
eports"), the information inside the web.config file of the Account folder still not encrypted, and I want to publish my site to the customer server. So, since this server is a customer server, then they can access this "web.config" file and change our web-application security behaviour (correct me if I am wrong). Basically, I don't want the customer to even have access to our secured pages when they access our web-application using the web browser. How to solve this issue?

View 2 Replies

Security - Encrypting Web Configuration Sections In 3.5?

Mar 9, 2010

Is there any tools available to encrypt and decrypt Asp.net Web configuration sections like connection string ,etc.?

Can i get any add-on for this?If i use Enterprise Library i can do so,but without that is there any simple utility available?

View 1 Replies

Security :: Encrypting And Decrypting Data

Aug 24, 2010

I have a webApplication in which i want to encrypt the data using Public key and whan it reach to the destination webapplication it will decrypted there with corresponding private key . Is there is any way to creating this pair of key?

View 3 Replies

Security :: Encrypting And Decrypting Password?

Apr 22, 2010

I want to encrypt the password entered by the user....how do i go about it?is there any built-in function for it or will i be required to write a code for it?

View 5 Replies

Security :: Encrypting Passwords On Client?

Nov 1, 2010

I want the login password to not be sent in plaintext (due to the risk of hijacking). I know that this can be achieved in principle using MD5 or the like, but is there a common implementation for use with Asp.Net? Of course, it's crucial that the resulting hash (?) isn't easy to decrypt. When I read various posts on this matter, some people say it's just to do a reverse on the encrypted string, so that in effect, this is totally useless.

View 6 Replies

Security :: Ways Of Encrypting Querystrings?

Sep 8, 2010

I have been looking at ways of encrypting querystrings and I have found a few good examples.. but, I just want some clarification on what is most often referred to as the EncryptionKey and the characters that are in that key....Is there basically an unlimited number of alphanumeric combinations that could be used in the following code as the encryption key, is there anything that someone should be CAREFUL about including in that key?

using System.Security.Cryptography;
private static string EncryptionKey = "!#$a54?3";
/// other examples: "r0b1nr0y"
///in a try-catch:
key = System.Text.Encoding.UTF8.GetBytes(EncryptionKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(Input);

View 3 Replies

Security :: Deploying And Encrypting Web.Config On Server

Nov 12, 2010

I have written a couple methods that encrypt and decrypt the appSettings section of my web.config file using the WebConfigurationManager. I just hooked up the methods to the page_load event to test that it works, which it does. Now I need to deploy to a web farm and need advice. What is the best way to make it so I can encrypt, but more importantly decrypt the web.config when I need to? I thought about putting a hidden page with "encrypt" and "decrypt" buttons, but that seems risky. What is the "accepted" method for rolling out something like this?

View 1 Replies

Security :: Encrypting / Decrypting Data At Runtime

Feb 18, 2010

I have a problem hopefully someone out there will steer me in the right direction.

I have a web application that I am going to put on a standalone cd - currently the data is "Safe" because the database is in in the app folder and the code is located in the codebehind.

My problem is i'm putting this on a CD as a standalone site, anyone can access the database, or find the XML....

Is there a way to generate an encrypted Database / XML Page, that is complied with the CD, that the program can decrypt and access with a embedded key?

View 1 Replies

Security :: Encrypting Passwords With T-SQL That Will Be Decrypted By Asp.net Membership Provider

Mar 4, 2011

I have been killing myself over this for a couple weeks now and cannot find a viable solution. Here's my scenario:

I have a DTSX package that imports user data from an external database. It then creates user accounts and profiles in the local database. Users can also be created via a custom ASP.NET Membership Provider. The provider must be able to authenticate both types of users.

This was all fine and dandy during development because passwords were stored as clear text. However, now that we're ready for release the passwords format of the provider must be set to encrypted and so the users created via the DTSX must be created with an encrypted password. (I'd prefer the passwords were hashed but the client's requirements are that passwords be recoverable). The real problem seems to be creating an encrypted password within the DTSX that will be decryptable by the ASP.NET Membership Provider.

My original solution was to have the DTSX call a CLR stored procedure that had access to the same encryption logic as the provider. I got it working but our client wouldn't enable CLR integration. So that's out the window. Now I'm investigating alternatives. One alternative is to simply use the built-in encryption methods of T-SQL. But how do I share the keys used for the encryption/decryption?

My question is, is it possible to generate a password in T-SQL, say using EncryptByKey, that will also be decryptable by my provider? This means that the key in SQL must match the key in my machineKey configuration.

View 2 Replies

Security :: Encrypting/Decrypting A Shared Password At Rest?

Dec 14, 2010

I received some code, a small c# asp.net application which manually posts a shared username/pwd to a 3rd party website for auto-logins from our intranet site. During transit the password is encrypted, but not within the application. Within this application a namevaluecollection is used and the username and password are hard coded. Originally the thought was, who cares if its hard coded because its shared between everyone anyway. Now we want to encrypt the username and password from within the application. I'm not sure the best way to accomplish the goal of making sure the password is encrypted "at rest". Normally I've seen passwords stored and encrypted within a database. I know we'll obviously have to move the password out of the application and store it somewhere else, I'm just not sure where. Do we move the username and pwd to the web.config file? I really am not sure the best way to approach this.

View 1 Replies

Security :: Encrypting Config File's Connection String And Keys?

Sep 23, 2010

Is aspnet_regiis.exe secure? If i encrypt using aspnet_regiis.exe, will it automatically decrypt the string and wont give any error? Need an insight into this stuff.... Is Rsa the best option or wat? Wat's the best way to encrypt/decrypt programmatically?

View 10 Replies

Security :: When To Use An Ssl Certificate

Jan 23, 2011

If I'm taking a password on a page, should that page be served via https and exactly how dangerous is it not to? I've tried googling this but every guide just says that ssl certificates "stop hackers seeing sensative data" with no real description of how they would do this or exactly how vulnerable your site is as a result of not having ssl.Could someone summarize how easy it is for someone to steal passwords on non-https pages? Should i even be considering doing a login page without one?

View 4 Replies

Security :: Encrypting Connection String In Web.config In Shared Hosting Environment?

May 27, 2010

My problem is that I'm going to have a SQL Server database and website that accesses that database via a hosting provider, most likely GoDaddy.com, using ASP.Net. I need to make sure the connection string in the web.config file is as secure as possible, because the database will actually be storing trivia questions for a game I'm developing, and the clients will be accessing these questions, saving specific state related details, and other details, to the database, so every player that plays the game will have their details stored in this database. I need to ensure hacking is very difficult to accomplish.

From my research it appears as though the only viable solution for your web.config when you've got a hosting account with something like GoDaddy.com is to use SQL Server security to connect to your SQL Server database and place those details in the web.config file. Is this correct? It seems that this is the most likely scenario for most users, because we don't have access to our hosting providers IIS servers in order to use Windows authentication with SQL Server access and then use DPAPI encryption from there.

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved