• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Encryption Code Problem
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Encryption Code Problem


  • Subject: Re: Encryption Code Problem
  • From: "Jonathan 'Wolf' Rentzsch" <email@hidden>
  • Date: Tue, 3 Jun 2003 15:17:53 -0500

Jonathan Fleming, email@hidden, wrote:
>><http://www.wodeveloper.com/omniLists/webobjects-dev/2002/July/msg00157.htm
>>l>
>
>Thanks for this Jonathan but that link seems to be dead. Is there an
>alternative way of obtaining this?

That link worked for me this AM, and works for me now. I'll include the
code here.

//
//	========================================================================
===
//
//	Title:		HexCoder.java
//	Description:	[Description]
//	Author:		Petite Abeille <email@hidden>
//	Creation Date:	Sat Sep 08 2001
//	Legal:		Copyright (C) 2001 Petite Abeille. All Rights Reserved.
//			This class is hereby released for all uses.
//			No warranties whatsoever.
//
//	------------------------------------------------------------------------
---
//

public final class HexCoder extends Object
{

//	========================================================================
===
//	Constant(s)
//	------------------------------------------------------------------------
---

	private static final char[]	Map = { '0', '1', '2', '3',
						'4', '5', '6', '7',
						'8', '9', 'A', 'B',
						'C', 'D', 'E', 'F' };

//	========================================================================
===
//	Class variable(s)
//	------------------------------------------------------------------------
---

//	========================================================================
===
//	Instance variable(s)
//	------------------------------------------------------------------------
---

//	========================================================================
===
//	Constructor method(s)
//	------------------------------------------------------------------------
---

	private HexCoder()
	{
		super();
	}

//	========================================================================
===
//	Class method(s)
//	------------------------------------------------------------------------
---

	public static String encode(byte[] someBytes)
	{
		if ( someBytes != null )
		{
			StringBuffer	aBuffer = new StringBuffer();
			int 		anIndex = someBytes.length;

			while( anIndex > 0 )
			{
				byte	aByte = someBytes[ --anIndex ];

				aBuffer.append( HexCoder.Map[ ( ( aByte >> 4 ) & 0x0f ) ] );
				aByte &= 0x0f;
				aBuffer.append( HexCoder.Map[ aByte ] );
			}

			return aBuffer.toString();
		}

		throw new IllegalArgumentException( "HexCoder.decode: null bytes." );
	}

	public static byte[] decode(String aString)
	{
		if ( aString != null )
		{
			int	aLength = aString.length();
			byte[]	someBytes = new byte[ aLength / 2 ];
			int	anIndex = 0;
			int	anotherIndex = aLength / 2;
			char[]	someChars = aString.toCharArray();

			while( anIndex < aLength )
			{
				char	upperChar = someChars[ anIndex ];
				char	lowerChar = someChars[ anIndex + 1 ];

				someBytes[ --anotherIndex ] = (byte)( ( HexCoder.charToNibble(
upperChar ) << 4 ) + HexCoder.charToNibble( lowerChar ) );

				anIndex += 2;
			}

			return someBytes;
		}

		throw new IllegalArgumentException( "HexCoder.decode: null string." );
	}

	private static int charToNibble(char aChar)
	{
                if ( ( aChar >= '0' ) && ( aChar <= '9' ) )
                {
                        return aChar - '0';
                }

		if ( ( aChar >= 'A' ) && ( aChar <= 'F' ) )
                {
                        return aChar - 'A' + 10;
                }

		if ( ( aChar >= 'a' ) && ( aChar <= 'f' ) )
                {
                        return aChar - 'a' + 10;
                }

		return 0;
	}

//	========================================================================
===
//	Instance method(s)
//	------------------------------------------------------------------------
---

}

.......................................................
Jonathan 'Wolf' Rentzsch            http://rentzsch.com
Red Shed Software   http://redshed.net   (847) 584-7465
PGP: b2af 1a09 f881 ebde c9d6  c4d2 c04f a3c0 3ec5 d5f2

         "better" necessarily means "different"
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Encryption Code Problem
  • Next by Date: RE: How should password be stored in Database?
  • Previous by thread: Re: Encryption Code Problem
  • Next by thread: Re: Encryption Code Problem
  • Index(es):
    • Date
    • Thread