Monday, March 1, 2010

Summary for file encryption and decryption

Import IO and Security.Cryptography

File Decryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
st = str1.Split("."c)
save_path = path & "\" & st(0) + "." & st(1)
Dim i As Integer = 0
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateDecryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()

File Encryption
Dim ue As New UnicodeEncoding()
Dim key As Byte() = ue.GetBytes(pword)
Dim rm As New RijndaelManaged()
Dim fs1 As New FileStream(file_path, FileMode.Open)
path = save_path
Dim str As String(), st As String()
str = file_path.Split("\"c)
Dim str1 As String = str(str.Length - 1)
save_path = path + "\" + str1 + ".cpt"
Dim i As Integer = 0
While (True)
If File.Exists(save_path) Then
st = str1.Split("."c)
i = i + 1
save_path = path + "\" & st(0) & "(" & i & ")" & "." & st(1) & ".cpt"
Else
Exit While
End If
End While
Dim fs2 As New FileStream(save_path, FileMode.Create)
Dim cs As New CryptoStream(fs2, rm.CreateEncryptor(key, key), CryptoStreamMode.Write)
While (True)
Dim d As Integer
d = fs1.ReadByte()
If d = -1 Then
Exit While
End If
cs.WriteByte(Convert.ToByte(d))
End While
cs.Close()
fs1.Close()

Write values in registry

First import Microsoft.win32

'select a prticular registry directory
registrydirectory = Registry.LocalMachine.OpenSubKey("SOFTWARE", True)
'createt ou own registry directory
registrydirectory.CreateSubKey("MyDir")

'open our own registry directory
registrydirectory = Registry.LocalMachine.OpenSubKey("Software\MyDir", True)
'write values and version
registrydirectory.SetValue("String Type", "String Data")
registrydirectory.Close()

Connection String Using Access 2007

cn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + "Location with filename as String" + ";Jet OLEDB:Database Password=;"

Script for adjust the web pages as center

function align()
{

var lmt = document.getElementById('center');
var container = document.documentElement;

if(lmt && container)
{
var containerHeight;
if (container.innerWidth)
{
containerHeight = container.innerHeight;
}
else
{
containerHeight = container.clientHeight;
}
var lmtHeight;
if (lmt.innerWidth)
{
lmtHeight = lmt.innerHeight;
}
else
{
lmtHeight = lmt.offsetHeight;
}
var y = Math.ceil((containerHeight - lmtHeight) / 2);
if(y <>
{
y = 0;
}
lmt.style.position = "relative";
lmt.style.top = y + "px";
}
if (document.getElementById)
{
document.body.style.visibility = 'visible';
}

}

function addevent(obj,evt,fn,capt){
if(obj.addEventListener)
{
obj.addEventListener(evt, fn, capt);
return true;
}
else if(obj.attachEvent)
{
obj.attachEvent('on'+evt, fn);
return true;
}
else return false;
}

if (document.getElementById && document.getElementsByTagName)
{
addevent(window, 'load', align, false);
addevent(window, 'resize', align, false);
}