C0ns0l3art's Bl0g

I am starting with the man in the mirror

Encrypt and Decrypt – Basic version

This is a basic version of encrypt-decrypt function…we used this from one of the .NET sites, since i am not able to find teh reference link , iam posting it here so that others can use it…
public class MyEnctDect
{
private Byte[] key = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24 };
private Byte[] iv = { 65, 110, 68, 26, 69, 178, 200, 219 };

public string Encrypt(string plainText)
{
//’ Declare a UTF8Encoding object so we may use the GetByte
//’ method to transform the plainText into a Byte array.
String outString;
UTF8Encoding utf8encoder = new UTF8Encoding();
Byte[] inputInBytes = utf8encoder.GetBytes(plainText);
//’ Create a new TripleDES service provider
TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
//’ The ICryptTransform interface uses the TripleDES
//’ crypt provider along with encryption key and init vector
//’ information
ICryptoTransform cryptoTransform = tdesProvider.CreateEncryptor(key, iv);
//’ All cryptographic functions need a stream to output the
//’ encrypted information. Here we declare a memory stream
//’ for this purpose.
MemoryStream encryptedStream = new MemoryStream();
CryptoStream cryptStream = new CryptoStream(encryptedStream, cryptoTransform, CryptoStreamMode.Write);
//’ Write the encrypted information to the stream. Flush the information
//’ when done to ensure everything is out of the buffer.
cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
cryptStream.FlushFinalBlock();
encryptedStream.Position = 0;
//’ Read the stream back into a Byte array and return it to the calling
//’ method.
// Dim result(encryptedStream.Length – 1) As Byte
byte[] result = new byte[encryptedStream.Length];
encryptedStream.Read(result, 0, (int)encryptedStream.Length);
cryptStream.Close();
//’test section
//’Convert to / fro the memory stream to a base64 string
//’compare decText to result
outString = System.Text.ASCIIEncoding.Default.GetString(result);

string encText = Convert.ToBase64String(encryptedStream.ToArray());
byte[] decText = Convert.FromBase64String(encText);
string sDec = Decrypt(decText);
return outString;
}

public String Decrypt(Byte[] inputInBytes)
{
//’ UTFEncoding is used to transform the decrypted Byte Array
//’ information back into a string.
UTF8Encoding utf8encoder = new UTF8Encoding();
TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
//’ As before we must provide the encryption/decryption key along with
//’ the init vector.
ICryptoTransform cryptoTransform = tdesProvider.CreateDecryptor(key, iv);
//’ Provide a memory stream to decrypt information into
MemoryStream decryptedStream = new MemoryStream();
CryptoStream cryptStream = new CryptoStream(decryptedStream, cryptoTransform, CryptoStreamMode.Write);
cryptStream.Write(inputInBytes, 0, inputInBytes.Length);
cryptStream.FlushFinalBlock();
decryptedStream.Position = 0;
//’ Read the memory stream and convert it back into a string
Byte[] result = new byte[decryptedStream.Length];
decryptedStream.Read(result, 0, (int)decryptedStream.Length);
cryptStream.Close();
UTF8Encoding myutf = new UTF8Encoding();
return myutf.GetString(result);
}
}
usage
MyEnctDect classDeclartion = new MyEnctDect();
classDeclartion.Encrypt(text);
classDeclartion.Decrypt(bytearray);

Its a good one for beginners, there are other methods available as well

October 24, 2009 Posted by consoleart | .NET, Beginner, C# | , , | 1 Comment

Creating controls with javascript

Thought this will be helpful for beginners

Create static combo
Create password field
create textbox
create textarea, all samples are subject to COPY rights…i mean you can use them for freee…

function CreateStaticCombo(sCtrlId, Width, list, value, defaultValue) {

var optGroup = document.createElement(’select’)
var arr = list.split(‘###’);

optGroup.setAttribute(‘className’, ‘ComboBoxStyle’);
optGroup.onblur = function() { };
optGroup.id = sCtrlId;
optGroup.name = sCtrlId;

var objOption = document.createElement(“option”)
objOption.innerText = “”;
objOption.value = “”;
optGroup.appendChild(objOption)

for (var i = 0; i < arr.length; i++) {
if (arr[i] != "") {
var objOption = document.createElement("option")
objOption.innerText = arr[i];
objOption.value = arr[i];

if (arr[i] == value.trim())
objOption.selected = true;

optGroup.appendChild(objOption)
}
}
optGroup.style.border = 0;
optGroup.onkeyup = function() { };
return optGroup;

}

function CreateLookupIcon(sCtrlId, IsLookupConditionAvailable) {
var imageNode = document.createElement("input");
imageNode.type = 'image';
imageNode.id = "imagetext"
imageNode.src = '../images/asmall.gif';

imageNode.onclick = function() { someJavascriptFunction(someParameters); return false; };
return imageNode;
}
function CreateHiddenField(sCtrlId) {
var txtbox = document.createElement('input');
txtbox.type = 'hidden';
txtbox.id = sCtrlId.replace('TD', 'D');
txtbox.name = sCtrlId.replace('TD', 'D');
return txtbox;
}

function CreatePassword(sCtrlId) {
var txtbox = document.createElement('input');
txtbox.onblur = function() { SetHiddenValue(this.id, this.value); EvaluateExpression('ALL', sCtrlId.toString().split('~')[2]) };
txtbox.type = 'password';
txtbox.passwordText = '*';
txtbox.id = sCtrlId;
txtbox.name = sCtrlId;
txtbox.setAttribute('className', 'MVTextBoxStyle');
txtbox.style.border = 1;
txtbox.style.bordercolor = "black";
txtbox.style.borderStyle = "solid"
return txtbox;
}

function CreateTextArea(sCtrlId, Width) {
var txtbox = document.createElement('textarea');
txtbox.rows = "2";
txtbox.style.height = "40px";
txtbox.onblur = function() { SetHiddenValue(this.id.replace('txt', ''), this.value); EvaluateExpression('ALL', sCtrlId.toString().split('~')[2]) };
txtbox.id = "txt" + sCtrlId;
txtbox.name = "txt" + sCtrlId;
txtbox.setAttribute('className', 'MVTextBoxStyle');

return txtbox;
}

October 23, 2009 Posted by consoleart | Beginner, javascript | , | 1 Comment

Configure SVN using windows

I came across this google search, but the page seemed to be deleted or moved away, so here is the original article on how to configure SVN using windows….the credit goes to the original author and not to me…I have just blogged it for reference purposes…

Setting up a Subversion Server under Windows

I talked a little bit about what Subversion is in my previous post. Now, let’s get it set it up in Windows.

Luckily for us, Joe White has done most of the work already; he has a tremendously helpful post that documents how to set up Subversion. I’ll see if I can streamline his excellent post a bit further, and illustrate it with screenshots.

A) Download Subversion

You’ll need the latest version of..

B) Install Subversion

  1. Unzip the Windows binaries to a folder of your choice. I chose c:\program files\subversion\ as my path.
  2. Now, add the subversion binaries to the path environment variable for the machine. I used %programfiles%\subversion\bin\
  3. You’ll also need another environment variable, SVN_EDITOR, set to the text editor of your choice. I used c:\windows\notepad.exe

C) Create a Repository

  1. Open a command prompt and type
    svnadmin create "c:\Documents and Settings\Subversion Repository"
  2. Navigate to the folder we just created. Within that folder, uncomment the following lines in the /conf/svnserve.conf file:
    [general]
    anon-access = read
    auth-access = write
    password-db = passwd

    Next, uncomment these lines in the /conf/passwd file:

    [users]
    harry = harryssecret
    sally = sallyssecret

D) Verify that everything is working

  1. Start the subversion server by issuing this command in the command window:
    svnserve --daemon --root "C:\Documents and Settings\Subversion Repository"
  2. Create a project by opening a second command window and entering this command:
    svn mkdir svn://localhost/myproject

    It’s a standard Subversion convention to have three folders at the root of a project:

    /trunk
    /branches
    /tags

  3. At this point, Notepad should launch:

    Enter any comment you want at the top of the file, then save and exit.

  4. You’ll now be prompted for credentials. In my case I was prompted for the administrator credentials as well:
    Authentication realm:  0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
    Password for 'Administrator': *********
    Authentication realm:  0f1a8b11-d50b-344d-9dc7-0d9ba12e22df
    Username: sally
    Password for 'sally': ************
    
    Committed revision 1.

    Congratulations! You just checked a change into Subversion!

E) Start the server as a service

  1. Stop the existing command window that’s running svnserve by pressing CTRL+C.
  2. Copy the file SVNService.exe from the zip file of the same name to the subversion\bin folder.
  3. Install the service by issuing the following commands:
    svnservice -install --daemon --root "C:\Documents and Settings\Subversion Repository"
    sc config svnservice start= auto
    net start svnservice
  4. Test the new service by listing all the files in the repository:
    svn ls svn://localhost/

    You should see the single project we created earlier, myproject/

F) Set up the shell extension

  1. Run the TortoiseSVN installer. It will tell you to restart, but you don’t need to.
  2. Create a project folder somewhere on your hard drive. Right click in that folder and select “SVN Checkout…”

    type svn://localhost/myproject/ for the repository URL and click OK.

  3. Create a new file in that directory. Right click the file and select “TortoiseSVN, Add”

  4. The file hasn’t actually been checked in yet. Subversion batches any changes and commits them as one atomic operation. To send all your changes to the server, right click and select “SVN Commit”:

And we’re done! You now have a networked Subversion server and client set up on your machine. Note that the default port for svnserve is 3690.

June 5, 2008 Posted by consoleart | Beginner, Linux, Windows | , , , | 2 Comments

Installation of Fedora

Prior to my previous post about moving to Linux. I have made a bold step, uninstalled my Vista once and for all, and now have my new OS as Fedora 8.

I first messed up with the installation, the installation does not proceed further after the message “Initializing boot…”, i reinstalled again and all worked so fine…

1) my resolution was messed up a little, i selected 1280 x something and my screen was way too away, the changed the resolution back(System –> Preferences –> HArdware –> Screen resolution) – as easy as that….

2) now I’m starting to play around, using the multiple work spaces,one always has my music player so that my current workplace, does not look messy at all(i always longed for this feature in windows –> even thou there were program groups –> it still did not have this multiple wrkspace thing, my first love with linux

3) there are some 128 updates available and my download manager is still downloading them(for more than 2 hrs now), so i will have my patience in letting it to complete…

I’m now trying to host my webserver and see how i can use Linux for websites…

jst a screen shot of my desktop as of now…more later…love to all who have helped me…thnx

this is my desktop

March 1, 2008 Posted by consoleart | Beginner, Linux | , , , | No Comments Yet

Changing my citizenship to Linux

I have been so desperate to move to Linux environment for quite sometime, just not becos many people say ITS GREAT, but becos i want to see whatz so great. By work I develop MS.NET applications and so have to stick to Windows series, as there is not much options available, but since I know PHP/JAVA, i preferred to have Linux at my home.

So i started to Digg on articles that contains the key word “Linux Vx Windows” “Ubuntu” “Fedora” and found that its very convincing, which has made me to download Linux OS. Iam going to install it over the weekend. But if the open source community can help me with some insights on how to configure my Network (it may sound dump, but i think it will be helpful) / internet / wireless keyboard/mouse etc., you can jst give me a pointer, ofcourse i can google them, but i would like the expert comments from the community. Thanks for your help in advance, i will keep posting my experience on Linux soon….and finally special thnx to Matthew Helmke – whose article was very helpful for me to seriously migrate to Linux.

February 29, 2008 Posted by consoleart | Beginner, Linux | , , | 1 Comment