Posts

Showing posts from October, 2009

C# GPG Implementation

publicclass GPG
{
private ILog log = LogManager.GetLogger(MethodInfo.GetCurrentMethod().DeclaringType);

privateconststring DEFAULT_GPG_PATH = @"C:\Program Files\GNU\GnuPG\";

private const string DECRYPT_ARGS = @"--batch --output ""{0}"" --decrypt ""{1}""";
private const string ENCRYPT_ARGS = @"--batch --output ""{0}"" --encrypt --recipient ""{2}""""{1}""";

private string _gpgPath;

public GPG()
{
_gpgPath = DEFAULT_GPG_PATH;
}

public string GpgPath
{
set { _gpgPath = value; }
}

public string DecryptFile(string filePath)
{
string outFile;
if (filePath.EndsWith(".gpg"))
{
outFile = filePath.Remove(filePath.Length - 4, 4);
}else
{
ou…

PGP/GPG Encryption

Public/Private keys are used to send encrypted data between clients. The receiving client generates public/private key pair and sends the public key to all contributing clients. The contributing clients are using public key to decrypt the file. Receiving client is using the private key to encrypt the file. Private key should never be send to anyone outside!How to start?Download latest version of GnuPG from www.gnupg.orgGeneral Helpgpg --helpCreating public/private(secret) keygpg --gen-keyListing public/private keysgpg --list-keysExporting public keygpg --armor --export test@email > public.keyExporting private keygpg --armor –export-secret-key test@email > public.keyImporting keysgpg -–import key.txtDeleting secret keygpg --delete-secret-keys test@emailDeleting public keygpg --delete-keys test@emailChange passphrasegpg --edit-key test@email passwdEncrypt filegpg --batch --output "<outfile>" --encrypt --recipient test@email "<infile>"Encrypt file wi…

Update/Insert data from one table to another

createTABLE #Load(
id int,
[name] VARCHAR(20)
)

createtable #Data(
id int,
[name] VARCHAR(20)
)

SELECT * FROM #Data

INSERT INTO #Load
SELECT 1,'one'
UNIONSELECT 2,'two'

UPDATE dbo.#DataSET
[name]=l.[name]
FROM #Load l JOIN #Data i ON l.id = i.id

INSERT INTO #Data
SELECT l.* FROM #Load l
LEFTJOIN #Data i ON i.id = l.id
WHERE i.id ISNULL

SELECT * FROM #Data

DELETEFROM #Load

INSERT INTO #Load
SELECT 2,'updated two'
UNIONSELECT 3,'three'

UPDATE dbo.#DataSET
[name]=l.[name]
FROM #Load l JOIN #Data i ON l.id = i.id

INSERT INTO #Data
SELECT l.* FROM #Load l
LEFTJOIN #Data i ON i.id = l.id
WHERE i.id ISNULL

SELECT * FROM #Data

DROPTABLE #Load
DROPTABLE #Data

Resolving DLL version conflict

If you’re using a third party library which was compiled with old version of some common library (like log4net) you will get a dll conflict when you try to run it..Net allows you to do binding redirect in App.config as long as the publicKeyToken is the same between versions.<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="CommonLibrary" publicKeyToken="b32731d11ce58905" culture="neutral" />
<bindingRedirect oldVersion="1.0.0.1" newVersion="1.0.0.2" />
</dependentAssembly>
</assemblyBinding>
</runtime>

How to find public key for .NET dll or exe

Open Visual Studio Command Prompt Run sn program as below C:\>sn –T C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Accessibility.dllMicrosoft (R) .NET Framework Strong Name Utility  Version 2.0.50727.42
Copyright (c) Microsoft Corporation.  All rights reserved. Public key token is b03f5f7f11d50a3a

SyncToy v2.0

“SyncToy 2.0 for Windows is available as a free download from the Microsoft Download Center. The easy to use, customizable application helps you copy, move, rename, and delete files between folders and computers.”

Visual Studio Subversion plugin

Image

Moving ClickOnce publish directory

Set update location in Visual Studio to the new location in the publish/update section and publish to the old location.Change publish location to new location and publish again.

Fixing Expired ClickOnce Certificate

If certificate expired:Create new certificate (using Visual Studio)Use Renewcert (Method 3) + This code (renewcert.cpp)Create extended certificate (5years)Release AppIf certificate is about to expire skip first step