.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

C# .NET using a plain text string for a DESCryptoServiceProvider KEY and IV

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :Windows Application
Can someone please give me a solution to my problem below: I have this file encryption / decryption code which I found in the help docs... Well, all I want to do is use a custom 8 char password with the code... But I keep on getting this error: An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll Additional information: Specified key is not a valid size for this algorithm. What encoding should be used for the string to work? This line gives the error: DES.Key = ASCIIEncoding.ASCII.GetBytes(sKey); Please help me with a solution: using System; using System.IO; using System.Security; using System.Security.Cryptography; using System.Runtime.InteropServices; using System.Text; namespace CSEncryptDecrypt { class Class1 { // Call this function to remove the key from memory after use for security [System.Runtime.InteropServices.DllImport("KERNEL32.DLL", EntryPoint = "RtlZeroMemory")] public static extern bool ZeroMemory(IntPtr Destination, int Length); // Function to Generate a 64 bits Key. static string GenerateKey() { // Create an instance of Symetric Algorithm. Key and IV is generated automatically. DESCryptoServiceProvider desCrypto = (DESCryptoServiceProvider)DESCryptoServiceProvider.Create(); // Use the Automatically generated key for Encryption. return ASCIIEncoding.ASCII.Get

View Complete Post

More Related Resource Links

How to read a column of a sharepoint list to a text string field of infopath form?

My infopath form used to read these email addresses from a web service and web.config file. Now i would like to get these user email addresses from a contact list in a sharepoint server. I am trying to do this without writing any codes. Here is what i have done so far: 1. Adding a new "data connection to receive data from SharePoint library or List" where i selected Email Address column of the contact list. 2. I added a new Text Field and define a new rule with "Query using a data connection" defined above. When i try to access the newly created Text field above it always return empty as if the Query attached to it did not executed at all. What did i do wrong? Is there a better way? Thank you in advance for your help.

Searching plain-text files.

Hello, I was wondering if you guys could point me in the right direction toward implementing a page in my Web Form application that would be able to allow a user to search a text file which originally exists on a Window File share. Once the user searches for their text, I'd like the page to be split into two panes: One on the left that lists all the hits, each listing being a link which contains an excerpt of text around the link. And another pane on the right which shows the full text document with all the hits highlighted.Now, should I be loading the text file into a data base and be using something like Lucence .NET to search? Or is there a library of controls that can do all this for me already?By searching around the internet I've found bits and pieces of solutions to this problem, such as how to highlight result hits: http://www.knowdotnet.com/articles/highlightingsearchtext.htmlAnd how to perform database searches: http://www.asp.net/sql-server/videos/enabling-full-text-search-in-your-text-dataAm I going to have to painstakingly glue all these things together and write my own solution to this?Thanks for the help in advance.

Cleanest way of setting max string length for text in GridView cells?

I want to make sure that each row in the table is the height of one line of text only.  I know you can set RowStyle-Wrap="false", but I also don't want any really wide rows.  I know I can go through each cell on RowDataBound or something and cut it to a particular length and then append an ellipsis on the end, but is there a neater way of doing the same thing?

Need to convert query string(date - 09/15/2010) to a text format - yyyymmdd

I am fairly new to C # and need some assistance with a form page.  I have created a simple form that requires the user to select a beginning date and ending date.  I then pass the values to my code behind page via query strings.  I have them passing, but I need the format to be change to a different format.  Unfortunately the database does not use the standard date format.  It requires the date to be in a text format as YYYYMMDD.Form: <tr> <td> Beginning Date:</td> <td><asp:TextBox runat="server" ID="begDate"></asp:TextBox> <asp:Image ID="Image2" ImageUrl="~/images/calendar_schedulehs.png" runat="server" /></td> </tr> Code Behind: protected void createReport_Click(object sender, EventArgs e) { StringBuilder url = new StringBuilder("Report/TopCustomer.aspx?"); url.Append("BegDate=" + begDate.Text); url.Append("&EndDate=" + endDate.Text); url.Append("&Brnch=" + ddlLocation.SelectedValue); Response.Redirect(url.ToString()); Current URL: TopCustomer.aspx?BegDate=09/15/2010&EndDate=09/30/2010&Brnch=300I need to have the above URL change to:TopCustomer.aspx?BegDate=20100915&E

How to: textbox text should show only the last part of the string

Hi, I have a textbox that shows info. (filename) When the filename is smaller than the width of the textbox all is fine, but when the filename is longer, i would like to show the last part of the filename in stead of the first part (default). Is this possible?

extract date from text string - Transact-SQL

Hello, I have a field in my database with an archived date... (Giampaoli  Live Oak, Almonds Archive 09/16/10) I need to be able to extract the date from this, then perform a datepart function on it... How do I extract the date into it's own value using just SQL? Thanks, Wes

Send a workflow email as plain text


I'm using a (SP designer) workflow to send e-mail alerts. I need to be able to send the e-mail in plain text because the recipient is an e-mail-to-SMS service that cannot handle HTML messages. I tried adding <pre> tags to my message, this causes the message to look like plaintext in Outlook, but is still sending the message as text/html type which isn't compatible with the aforementioned SMS service. Any ideas how I can make sharepoint send the messages as true plain text?

Mail server is Exchange 2003 SP2.


what can be used for pure text string in vb.net (it is @"string" in c#)


I am trying to dynamically create an xml file in vb.net, please look at the code below ;

            Dim detay As XmlElement = doc.CreateElement("title")
            detay.InnerText = "<![CDATA[<p><span class='footer' >Urun  No:8232-3   <a href='www.lasagrada.com.tr'>URUN DETAYLARI</a> icin lutfen web sitemizi ziyaret ediniz <a href='www.lasagrada.com.tr'> CANLI DESTEK </a></span></p>]]>"

            Dim detay As XmlElement = doc.CreateElement("title")

         detay.InnerText = "<![CDATA[<p><span class='footer' >any info <a href='anylink'>.....</a> sometext <a href='anysite'> teachers </a&

Problem extracting the middle characters of a text string


I need to extract a portion of text from one field and put it in another field and I am having trouble with the syntex.  I am doing this with an sql select statement in asp.net. 

I can select the left most characters of the field (SELECT  BatchNumber, LEFT(BatchNumber, 3) AS Expr1 FROM  DonorHistory) or the right most characters of the field (SELECT BatchNumber, RIGHT(BatchNumber, 3) AS Expr1 FROM DonorHistory) but I cannot select characters from the middle of the field.  I expected that to be able to use a statements such as "SELECT BatchNumber, mid(BatchNumber, 3, 2) AS Expr1 FROM DonorHistory" but this statement gives me an error.  I also tried using middle in place of mid but that did not work either.

What am I doing wrong?





Importing text file datetime string into SQL datetime column



Using SSIS 2008 R2 to import text files.  Two of the fields contained are datetime values in the format "2010-09-24 18:58:29.220".  Ultimately both the date and time need to be extracted with precision to the second, at the very least.  When I import the text file, however, the time value seems to get truncated before the date value's being imported, for an imported result of "2010-09-24 00:00:00.000".

Is my problem with the Flat File Connection Manager?  Regardless of which DataType choice I use for the properties of my datetime values--I've tried every form of date datatype--the imported column values contain the correct date but the wrong time value.

Is there an easy way to import a text file datetime value straight into a datetime column?  Is it possible, or am I trying to shortcut what should be a proper process?


Importing text file datetime string into SQL datetime column



I'm importing a text file into SQL Server 2008 R2 using SSIS 2008 R2.  Included in the text file is a datetime column with values like "2010-09-24 18:58:29.220".  However, when I import the file, the stored value has the time portion replaced with what I assume is the default, such as "2010-09-24 00:00:00.000".

Is there an easy way to import a datetime value from a text file into a datetime column in my table?  I've tried every form of date datatype in the Flat File Connection Manager, but I still keep getting the correct date portion with the incorrect time portion.

Am I trying to do something that wasn't intended?  I see Todd McDermid's page (http://toddmcdermid.blogspot.com/2008/11/converting-strings-to-dates-in-derived.html) and am starting to wonder if perhaps I'm trying to shortcut something that I shouldn't.


How do I send a workflow email in plain text

I'm using sharepoint designer to setup a workflow. My action is 'Send an Email'.  I have no problems sending the email, the problem is the email is always sent as HTML and I need it sent as plain/text as the application receiving this email only takes plain/text.  How do I send emails in plain text or is there an easy 2 step workaround?

OPENROWSET 'Provider String' Documentation? Firstrow for Text Driver, Column names in 3rd row


I'm using sql server 2008 r2 express and want to write a script to load data from some csv files.


The following gets me close:




        'Driver={Microsoft Text Driver (*.txt; *.csv)}; DEFAULTDIR=C:\Data\QOL;Extensions=CSV;',

        'SELECT * FROM RegistrationData.csv')


The problem is that the that the first two lines are not data (Report Name and time generated) and the third line is the column names. If I manually open the file and delete the first two rows everything comes out perfectly. But there are a number of these files and it has to be done regularly so I want to automate the process.  BULK options allow a FIRSTROW option but that doesn't seem to work w/o the BULK option. Is there a way to effectively skip the first 2 lines w/o the BULK option (and its requisite format file)?

Form Services 2010 - potential bug in plain text - multi-line boxes



Just wondering if anyone else has found the following and perhaps a resolution.  (Blog post with image examples here: Click)


An InfoPath Form created in Microsoft InfoPath Designer 2010 and is installed as an Administrator approved template.

  • Form Control: Text Box


  • Read-only – No
  • Enable spelling checker – Yes
  • Enable AutoComplete – Yes
  • Multi-line – Yes


  • Height: Auto

Compatibility Settings:

  • Form Type: Web Browser Form (2010)


  • Browser: Internet Explorer 7, 8, Google Chrome

When running the Form in the web and a user types into the multi-line text box; after 20 characters the text box gets bigger by 1 row.

On evaluation using the IE8 development toolbar.  It would appear that the control is rendered as a <textarea> HTML element and JavaScript runs on the 22<sup>nd</sup> character and adds 1 to the “rows” attribute of the <textarea> element.

For example:

hyperlink text/now create string from label? please help



I have a datalist in a page which shows a username in a label from the database (theiruseridLabel)

I'm trying to take this username, find its profile.firstname and profile.company name, and then display them as the text in 2 hyperlinks.

i have the code below, but this doesnt work..? can anyone see why? there is no error, just the hyperlinks just show as 'hyperlink' rather than the names i want. Thanks!:

HyperLink hp2 = DataList1.Items[0].FindControl("HyperLink2") as HyperLink;
        HyperLink hp3 = DataList1.Items[0].FindControl("HyperLink3") as HyperLink;
        Label theiruseridLabel = DataList1.Items[0].FindControl("theiruseridLabel") as Label;

        string userName = Request["theiruseridLabel"];
        ProfileCommon userProfile = System.Web.Profile.ProfileBase.Create(userName, true) as ProfileCommon;
        hp2.Text = userProfile.FirstName;
        hp3.Text = userProfile.CompanyName;

Embedding plain-text passwords



I'm looking to create my application as secure as possible. Now I have following line of code:

DirectoryEntry entry = new DirectoryEntry("LDAP://", "domain\username", "password", AuthenticationTypes.Secure | AuthenticationTypes.Sealing | AuthenticationTypes.Signing);

As you can see, my password is in plain-text in the code. Now, I presume it's easy to decompile a code using a tool and getting your hands on the password. Since these are my AD Admin-credentials this is not that good.

The AuthenticationTypes are secure, I think. They encrypt the data before sending it to the network.
So there's just the problem of the plain-text password. I've searched for it on Google but can't find the proper solution. I've found alot about encrypting passwords in the web.config. Is this the solution to my problem? 

How to Encrypt Query String Parameters in ASP.NET

Encrypt Query String Parameters in ASP.NET.u can send secure data one page another page u can also use query string to encrypt
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend