Friday, 9 May 2008

Gnu Privacy Guard Commands

GNU Privacy Guard (GPG) commands


http://www.gnupg.org/

This blog lists a load of gpg commands which are really useful!

Useful commands


What follows is a list of useful commands

Help (listing all available commands and options)

gpg --help

We get a full list of commands. Note all gpg commands take the format:

gpg [option1, option2, .. option n] [command] [Filename or user to work with]

Listing keys on keyrings

gpg -k (gpg --list-keys)

lists all public keys on the current users public keyring

gpg --list-secret-keys

lists all secret keys on the current users secret keyring

Generating a new private-public key

gpg --gen-key

Select the kind of key, size of encryption, and other details and give the key pair a name.

Importing a public key onto the keyring

Note you can import private keys this way as well.

gpg –import

Removing a key from the keyring

The following commands remove keys from the respective keyrings. Note if you try and remove a public key which has the same private pair then you will need to remove the private (secret) key first.

Public: gpg --delete-keys [Keyname]
Secret: gpg --delete-secret-keys [Keyname]

Exporting Public Key
To make key available for other users to decrypt with you can export the public key by using the command:

gpg -a -u [Local user with private key] --passphrase [Local user pass phrase] --export >[Name of file for exported public key]


Encrypting data

You can encrypt data with a private key using the following command

gpg -e -o [outputfilename] -u [Local Private Key User] [inputFilename]
gpg -e --output [outputfilename] -u [Local Private Key User] [inputFilename]

You can also armour the output with ascii with the following command:

gpg -ea -o [outputfilename] -u [Local Private Key User] [inputFilename]

Armouring makes the encrypted file more readable in text viewers.

If you omit the -o then it will save the file with an appended extension of .gpg

Decrypting data

The following commands can decrypt data encrypted by a specific public key. Note you need the public key of the pair which the private key was used to encrypt the data with.

eg. gpg -da -r [Public Key] [EncryptedFileName] >[NewFileName]

Note if you omit the pipe to the new file name then the decrypted output will be displayed to the screen.

You need to provide a pass phrase to decipher the encrypted file. You will either be prompted for this or you can use the –passphrase switch

eg. gpg -da --passphrase [PassPhrase] -r [Public Key] [EncryptedFileName] >[NewFileName]
Signing keys

When importing in public keys from the client to your public keyring you must sign the key. This can be done by

gpg -u [Local User with Private Key] --passphrase [Local user passphrase] --edit-key [Remote user with Public Key] sign

You will then need to hit yes and then quit to exit

Very Verbose messages :)

Always useful to get as much information returned back when having problems, Use the -vv (very verbose) option.

For example when you listing key information using the -vv option highlights if the public key has been signed.


Very useful resouces:

Justin Millers Guide
Click here to view

Wednesday, 5 March 2008

How to enable SVN Headers on source code

Quite easy really once you know how. Go to the top level of your checkout directory. Click properties, and select the subversion tab. See if svn:keywords is added - if it isn't then add it and in the value put the keywords you want to add. If it is there then just change the value. If directory click the recurse option and it will set the whole archive.

svn:keywords Date Revision Author HeadURL Id

Useful article: http://svnbook.red-bean.com/en/1.1/ch07s02.html

Getting rid of annoying orphaned users on a SQL Server 2005 database

A nice one of those microsoft errors this one!!

Trying to delete an old user on a database which i have restored, but there is a problem, it throws an error, 'Drop failed for User ABC' (Microsoft.SqlServer.Smo)

The database principal owns a schema in the database, and cannot be dropped. (Microsoft SQL Server, Error: 15138)

Oh Joy! Ok after digging around I tried this which returned a list of orphaned users:

select u.name from master..syslogins l right join
sysusers u on l.sid = u.sid
where l.sid is null and issqlrole <> 1 and isapprole <> 1
and (u.name <> 'INFORMATION_SCHEMA' and u.name <> 'guest'
and u.name <> 'system_function_schema')

With that I can use the exec sp_revokedbaccess 'ABC' - make sure they do not own any of the schemas in the database. You may need to move this onto another user.

Wednesday, 23 January 2008

NHibernate Provider for ASP.Net 2.0 membership and roles

Found this extremely useful blog on how to build an nhibernate custom provider for ASP.Net Membership role security.

http://www.codeplex.com/nhibernateprovider/

http://lvildosola.blogspot.com/2007/02/nhibernateprovider-moves-to-codeplex.html

Another individual trying to use nhibernate with membership providers

http://www.codeproject.com/KB/aspnet/eucalypto.aspx

Thursday, 17 January 2008

Useful simple type for Global Unique Identifier

Keep having to use this in schemas - so thought I would put this here..

This type will verify a global unqiue identifier:

<xs:simpleType name="GUID">
<xs:annotation>
<xs:documentation xml:lang="en">The representation of a GUID, generally the id of an element.</xs:documentation>
</xs:annotation>
<xs:restriction base="xsd:string">
<xs:pattern
value="\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}"/>
</xs:restriction>
</xs:simpleType>

Friday, 14 December 2007

Life is so much easier with RoyalTS

If you like me have to have several rdc's open at one time - and fed up with fleeting between each of them, RoyalTS from codeaward

http://www.code4ward.net/main/RoyalTS/Overview.aspx

Been using it for ages - but its such a good application - I had to blog about it.

Monday, 3 December 2007

Finding a good open source UML tool?

Ok we all want to design good software. Anyway for a new idea I had in mind, I wanted to design it properly instead of the usual fire-fight test and develop method, so I went in search for some tools which will help me detail a uml design.

As a good start I found the following page which lists many of the available tools with their features and limitations.

oose Innovative Informatik

Some of the tools are instantly recogniseable as I worked with several of them such as Enterprise Architect and Rational Rose. But funds are tight and if there is a free alternative up to the job then so much the better..

I then waded through the ones which claim to have no limitation to find an open source tool which would meet my requirements of developing a full enterprise level application.

ArgoUML

This looks very good pretty much I was looking for. Supports c# and php code generation. Reverse engineering is only java, but thats ok. It doesn't allow you to create database schemas like enterprise architect so will need to find another tool for that.

Astade

Unfortunately this only generates code in c++ and therefore is no use really for me. Although it seems simple to use which is definitely a benefit!

Umbrello UML Modeller

Great for linux! Has many of the features that ArgoUML has and seems to have a pretty useable interface.

StarUML

Another really good tool with lots of support. It also allows c# reverse engineering and has a series of additional modules such as non-functional requirements modelling and web extensions.

Fujaba

Interesting application but doesn't have everything I require.

I find this blog as well which had some interesting pointers: geekswithblogs

:)

Wednesday, 21 November 2007

Adding a new mailbox to you exchange settings in Outlook 2003

How to open another inbox to add to your mail folders in Outlook 2003. Make sure first you are delegate or have access to the box.

1. On the Tools menu, click E-mail Accounts.
2. Click View or change existing e-mail accounts, and then click Next.
3. Click the Exchange Server account, and then click Change.
4. Click More Settings.
5. On the Advanced tab, under Mailboxes, click Add.
6. Type the other user's name, and then click OK twice.
7. Click Next, and then click Finish.

Friday, 16 November 2007

Greenfish Icon Editor Pro

I found this really useful 'free' icon editor from a company in Hungary called Greenfish Corporation. Very handy.

NB: All over icon utilities I found on the net were shareware crap and didn't work that well.

Greenfish Icon Editor Pro

This program is a professional, yet easy to use tool for creating icons, cursors, and other small pixelgraphic images. It has a wide range of features, including:

* Opening and saving in ICO, CUR, PNG, XPM, BMP and JPEG formats
* Creating icons up to 256x256 @ 32-bit
* Creating Vista(tm)-compatible, PNG compressed icons
* Sophisticated selecting tools like marquee, lasso and magic wand, as in a professional photo editor
* Creating and testing cursors
* Extracting icons and cursors from executable files
* Dynamic color depth: you do not have to specify it explicitly, Greenfish Icon Editor will determine it for you.
* Painting easily in 32-bit
* Drawing lots of kinds of gradients
* Lots of filters including Remove matte, Drop shadow, Inner/Outer glow and Bevel
* Sample icons are included
* No installation required, Greenfish Icon Editor Pro is absolutely portable
* It is FREE!

Can get it from here.
Greenfish Corporation: "Lots of filters including Remove matte, Drop shadow, Inner/Outer glow and Bevel"

Thursday, 15 November 2007

Disabling the Window Close Button and System Close menu in a Windows Form

A useful snippet for disabling the X button on a window form in c#:

1. Use an api call to user32.api

Basically, this call uses GetSystemMenu() to get a handle to the menu with the close, maximize and minimize buttons. Then, the EnableMenuItem() call comes along and sets it so that the close button is greyed out (i.e. disabled).

NB. The code needs to go in the Paint handler because otherwise the changes to the close button will not be retained when the form is repainted (e.g. when you minimise and then restore).

C# Source:


Use these constants

///
/// Windows constant that represents the X button on a window
///
private const int SC_CLOSE = 0xF060;

///
/// Menu API Constant: Enables the menu item so that it can be selected and restores it from its grayed state.
///
private const int MF_ENABLED = 0;

///
/// Menu API Constant: Disables the menu item and grays it so it cannot be selected.
///
private const int MF_GREYED = 0x1;

///
/// Menu API Constant: Identifies menu item position by command.
///
private const int MF_BYCOMMAND = 0;

Then add references to the api windows methods:

///
/// Windows api call to get the system menu
///
/// hWnd Handle of window

/// revert Specifies the action to be taken. If this parameter is FALSE, GetSystemMenu returns a handle to the copy of the window menu currently in use. The copy is initially identical to the window menu, but it can be modified. If this parameter is TRUE, GetSystemMenu resets the window menu back to the default state. The previous window menu, if any, is destroyed.
/// returns variable: if the bRevert parameter is FALSE, the return value is a handle to a copy of the window menu. If the bRevert parameter is TRUE, the return value is NULL.
[DllImport("user32")]
private static extern IntPtr GetSystemMenu(IntPtr hWnd, int revert);

///
/// Windows api call to enabling a menu item
///
/// hWndMenu handle to the window menu
/// itemID item to enable
/// enable enable/disable/greyed
/// returns variable: The return value specifies the previous state of the menu item (it is either MF_DISABLED, MF_ENABLED, or MF_GRAYED). If the menu item does not exist, the return value is -1.
[DllImport("user32")]
private static extern int EnableMenuItem(IntPtr hWndMenu, int itemID, int enable);

This private field to represent if the close x is enabled/disabled

///
/// Flag to represent if a form window close x is enabled/disabled
///
private bool closeEnabled = false;

and finally a public property - so we can access this outside the form if required.

///
/// Property manages the visibility of the X close button on this form window
///
public bool CloseEnabled
{
get { return closeEnabled; }
set
{
//Decide on the state to pass based on the value being set
int setting = (value) ? MF_BYCOMMAND | MF_ENABLED : MF_BYCOMMAND | MF_GREYED;

try
{
EnableMenuItem(GetSystemMenu(this.Handle, 0), SC_CLOSE, setting);
}
catch { }
closeEnabled = value;
}
}


2) Set the 'ControlBox' property on the form to false

this.ControlBox = false;

However this disables the entire system menu strip - i.e. icon drop down etc. so may not be of use.

Also by holding down ALT-F4 - this often closes an application window and therefore you would need to capture this in the form_closing event - and set event args e to cancel.

i.e. e.cancel = false;