Click here to Skip to main content
12,625,355 members (40,424 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# PowerShell
I have got a build error in the following code....

string password = "Global12$";
string userName = @"myindia.local\Administrator";
SecureString ss = ConvertToSecureString(password);

This is the error message

The name 'ConvertToSecureString' does not exist in the current context

I don't know how to solve this? Which namespace is missing? Any help on this would be great.

Thanks & Regards
Sebastian
Posted 15-Jun-12 3:51am
Updated 17-Jun-12 20:20pm
v2
Comments
ryanb31 15-Jun-12 8:58am
   
A quick google search indicates using ConvertTo-SecureString. Have you tried that?
Sebastian T Xavier 15-Jun-12 9:22am
   
If you can show some examples of this , that would be great!!!
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Not sure if this is what you're looking for, but try this link:
ConvertToSecureString Class[^] on MSDN.
It has some examples there.
Edited: This can't be the right answer :)

On second thought look at the comments at the bottom here[^]

Maybe that's where this mysterious method came from ;)

private SecureString ConvertToSecureString(string value)
{
    SecureString ret = new SecureString();
    foreach (char c in value)
    {
        ret.AppendChar(c);
    }
    ret.MakeReadOnly();
    return ret;
}
  Permalink  
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

ConvertToSecureString is a private method , which you need to write in your own class.

As mentioned http://msdn.microsoft.com/en-us/library/system.security.securestring.aspx[^], you need to write your own version of ConvertToSecureString method.

Thanks
Rushikesh Joshi
  Permalink  
Comments
Sebastian T Xavier 18-Jun-12 1:19am
   
Thanks for your reply. But I think , I am looking for another method. Please have a look at the following URL. http://msdn.microsoft.com/en-us/library/microsoft.powershell.security.activities.converttosecurestring(v=vs.85).aspx.

Regards
Sebastian

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161128.1 | Last Updated 18 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100