Data Encryption using SQL Server 2005

Many times need to encript/decript data from my database. If I want to Encrypt/Decrypt my database using SQL Server2005

I need to do some task.

Step:1
I have to enable database encryption.

Syntax: ALTER DATABASE <<db_name>> SET ENCRYPTION ON

Step:2
I have to create a master key using my own password

Syntax: CREATE MASTER KEY ENCRYPTION BY PASSWORD = <<my_password>>

Step:3
I have to create a certificate

Syntax: CREATE CERTIFICATE <<certificate_name>> WITH SUBJECT = <<subject_name>>

Step: 4
I have to create symmetric key

Syntax: CREATE SYMMETRIC KEY <<key_name>> WITH ALGORITHM = TRIPLE_DES ENCRYPTION BY CERTIFICATE <<certificate_name>>

Step: 5
I have to Open symmetric key when required insert/update/select operation.

Syntax: OPEN SYMMETRIC KEY <<key_name>> DECRYPTION BY CERTIFICATE <<certificate_name>>

Step:6
I have to use built in function for encrypt data.

Syntax: CREATE TABLE Test(Name varchar(50) not null);

INSERT INTO test VALUES (EncryptByKey(Key_GUID('key_name'), 'habib1'));

SELECT CAST(DecryptByKey(name) AS varchar) FROM test;

Step:7
Close My open symmetric key

Syntax: CLOSE SYMMETRIC KEY <<my_key>>;


There are also many algorithms you can use for sqlserver dataencryption. I use only TRIPLE_DES.

Parent window refresh & Chield window close without confirmation

Many Times it is required to close Refresh parent winsow then close Chield window without confirmation. It is very common senario. I know everybody knows it. But sometimes not remember. So i publish it.

<script type="text/javascript">

window.opener.location.href='Parent.aspx';
window.open('','_parent',''); window.close();

</script">

When you refresh your parent page, that time you loose all view state data. Many times client want to see controls showing data. If so then you need to write code to maintain data of control. Then you may create any class which can store pages last data to session and when required it retrive data from that also.

Retrive ProcessorID, HardDiskID, LANCardID, MotherboardID using c#

Many times it is required to retrive processor, harddisk, lancard,
motherboard
identification for the purpose of Licenseing Issue.
So my code is helpful for you if you interested to manage license for
your application. You just receive clients webservers the above
information
first time, latter when User want's to lunch his/her appliation, then
you check it with the help of webserver which is hosted by you.

Requirement
==========
If you want to implement that model then you must host and live your
webserer. ohterwise clients app does not work. If you not like that then
you may change that model and implement any dirrerent technic for
license checking.


The code is written by dotnet 2.0/3.0/3.5
===========================================

using System.Management;
using System.Management.Instrumentation;

public string GetProcessorID()
{
string processorID = string.Empty;

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_Processor");


foreach (ManagementObject o in searcher.Get())
{
foreach (PropertyData prop in o.Properties)
{
if (prop.Name.Equals("ProcessorId"))
{
processorID = (String)prop.Value;
break;
}
}
}
return processorID;
}

public string GetDiskID()
{
string diskID = string.Empty;

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_DiskDrive");


foreach (ManagementObject o in searcher.Get())
{
foreach (PropertyData prop in o.Properties)
{
if (prop.Name == "Caption")
{
diskID = (String)prop.Value;
break;
}
}
}
return diskID;
}


public string GetMotherBoardSerialNumber()
{
string serialNumber = string.Empty;

ManagementObjectSearcher searcher = new
ManagementObjectSearcher("select * from Win32_BaseBoard");


foreach (ManagementObject o in searcher.Get())
{
foreach (PropertyData prop in o.Properties)
{
if (prop.Name == "SerialNumber")
return (String)prop.Value;
}
}
return serialNumber;
}



public string GetMacAddress()
{
string result = string.Empty;

foreach (NetworkInterface obj in
NetworkInterface.GetAllNetworkInterfaces())
{
if (obj.NetworkInterfaceType !=
NetworkInterfaceType.Loopback)
{
result = obj.GetPhysicalAddress().ToString();
break;
}
}
return result;
}