Java Doc for EncryptionHelper.java in  » J2EE » Jaffa » org » jaffa » security » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Jaffa » org.jaffa.security 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.jaffa.security.EncryptionHelper

EncryptionHelper
public class EncryptionHelper (Code)
This class has some utility functions for encrypting objects using the JCE Security Package. Its main purpose is to be able to take a Object/String and encrypt it, and then convert the encrypted data into a HexString, so that it can be passed arround as a String, and hence used in URL's. A good exmple of this is if you have an Object that you want to pass to a servlet, then you can use this routine to get a HexString version of that object and pass it accross in the URL as a paramater "data=1234567890ABC...", Data will not only be a serialization of the object, it will also be encrypted with a SecretKey, that the recievoing servlet must use when converting it back to an object. The String version of this process is optimized to convert the String in to a UTF-8 byte array. This results in a much smaller string then regular obejct serialization.
author:
   paule
version:
   1.0


Field Summary
final public static  StringENCRYPT_POLICY
    


Method Summary
public static  SecretKeycreateKey()
     This method can be used from the command line for creating a Secret Key.
public static  StringencryptObjectForURL(Object source, SecretKey key)
     Creates an encrypted and encode string from the source object.
public static  StringencryptStringForURL(String source, SecretKey key)
     Creates an encrypted and encode string from the source string.
public static  bytefromHex(char c)
     Utility function to convert a hex character to a number.
public static  byte[]fromHexString(String in)
     Convert a String of hex values into a byte[].
public static  ObjectgetObjectFromEncryptedURL(String data, SecretKey key)
     Get an Object from an Encoded and Encrypted String.
public static  StringgetStringFromEncryptedURL(String data, SecretKey key)
     Get a String from an Encoded and Encrypted String.
public static  byte[]intoBytes(String in)
     Converts a String (based on an 8-bit character set) into an byte array. There will be one byte per charater in the string.
Parameters:
  in - The string to be converted
throws:
  UnsupportedEncodingException - Is thrown if there are any unsupported characters in the string (ie.
public static  byte[]intoBytes16(String in)
     Converts a String into an byte array.
public static  StringintoHexString(byte[] in)
     Converts a byte[] into a hex string representation.
public static  StringintoString(byte[] in)
     Converts a byte array into a string.
public static  StringintoString16(byte[] in)
     Converts a byte array into a string.
public static  voidmain(String args)
     This method can be used from the command line for creating a Secret Key.
public static  SecretKeyreadKey(File file)
    
public static  SecretKeyreadKeyClassPath(String name)
    
public static  chartoHex(byte b)
     Utility function to convert a number into a hex character.

Field Detail
ENCRYPT_POLICY
final public static String ENCRYPT_POLICY(Code)
This is the encryption policy that will be used





Method Detail
createKey
public static SecretKey createKey()(Code)
This method can be used from the command line for creating a Secret Key. Returns the newley generated key, or null if there was an error.



encryptObjectForURL
public static String encryptObjectForURL(Object source, SecretKey key) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, javax.crypto.NoSuchPaddingException, java.io.UnsupportedEncodingException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException, java.io.NotSerializableException(Code)
Creates an encrypted and encode string from the source object. This string can be used directly in a URL without encoding. This assumes that the object passed in can be serialized.
Parameters:
  source - The source Object to encrypt/encode
Parameters:
  key - The secret key to use for encryption
throws:
  NoSuchAlgorithmException - May be thrown by the Cypher module
throws:
  InvalidKeyException - May be thrown by the Cypher module
throws:
  NoSuchPaddingException - May be thrown by the Cypher module
throws:
  UnsupportedEncodingException - May be thrown by the Cypher module
throws:
  IllegalBlockSizeException - May be thrown by the Cypher module
throws:
  BadPaddingException - May be thrown by the Cypher module
throws:
  NotSerializableException - if the source object is not Serializable The encoded/encrypted string



encryptStringForURL
public static String encryptStringForURL(String source, SecretKey key) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, javax.crypto.NoSuchPaddingException, java.io.UnsupportedEncodingException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException(Code)
Creates an encrypted and encode string from the source string. This string can be used directly in a URL without encoding.
Parameters:
  source - The source string to encrypt/encode
Parameters:
  key - The secret key to use for encryption
throws:
  NoSuchAlgorithmException - May be thrown by the Cypher module
throws:
  InvalidKeyException - May be thrown by the Cypher module
throws:
  NoSuchPaddingException - May be thrown by the Cypher module
throws:
  UnsupportedEncodingException - May be thrown by the Cypher module
throws:
  IllegalBlockSizeException - May be thrown by the Cypher module
throws:
  BadPaddingException - May be thrown by the Cypher module The encoded/encrypted string



fromHex
public static byte fromHex(char c)(Code)
Utility function to convert a hex character to a number. The character must be '0'..'F', the byte will be 0-15.
Parameters:
  c - The character to convert The number as a byte



fromHexString
public static byte[] fromHexString(String in)(Code)
Convert a String of hex values into a byte[]. Each two characters in the string represent 1 byte.
Parameters:
  in - The hex string to be converted A byte[] of the real data



getObjectFromEncryptedURL
public static Object getObjectFromEncryptedURL(String data, SecretKey key) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, javax.crypto.NoSuchPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException(Code)
Get an Object from an Encoded and Encrypted String. This assumes that the object can be recreated by de-serialization, and that the original class for the object is accessable.
Parameters:
  data - The encoded/encrypted string to process
Parameters:
  key - The secret key used needed to decrypt the string
throws:
  NoSuchAlgorithmException - May be thrown by the Cypher module
throws:
  InvalidKeyException - May be thrown by the Cypher module
throws:
  NoSuchPaddingException - May be thrown by the Cypher module
throws:
  IllegalBlockSizeException - May be thrown by the Cypher module
throws:
  BadPaddingException - May be thrown by the Cypher module The real object that the data represents



getStringFromEncryptedURL
public static String getStringFromEncryptedURL(String data, SecretKey key) throws java.security.NoSuchAlgorithmException, java.security.InvalidKeyException, javax.crypto.NoSuchPaddingException, javax.crypto.IllegalBlockSizeException, javax.crypto.BadPaddingException(Code)
Get a String from an Encoded and Encrypted String.
Parameters:
  data - The encoded/encrypted string to process
Parameters:
  key - The secret key used needed to decrypt the string
throws:
  NoSuchAlgorithmException - May be thrown by the Cypher module
throws:
  InvalidKeyException - May be thrown by the Cypher module
throws:
  NoSuchPaddingException - May be thrown by the Cypher module
throws:
  IllegalBlockSizeException - May be thrown by the Cypher module
throws:
  BadPaddingException - May be thrown by the Cypher module The real string that the data represents



intoBytes
public static byte[] intoBytes(String in) throws UnsupportedEncodingException(Code)
Converts a String (based on an 8-bit character set) into an byte array. There will be one byte per charater in the string.
Parameters:
  in - The string to be converted
throws:
  UnsupportedEncodingException - Is thrown if there are any unsupported characters in the string (ie. greater that 8-bits) The byte[] for the string



intoBytes16
public static byte[] intoBytes16(String in)(Code)
Converts a String into an byte array. There will be two bytes per charater in the string.
Parameters:
  in - The string to be converted The byte[] for the string



intoHexString
public static String intoHexString(byte[] in)(Code)
Converts a byte[] into a hex string representation. Each byte will be represented by a 2-digit hex number (00-FF).
Parameters:
  in - The byte[] to convert The string containing the Hex representation



intoString
public static String intoString(byte[] in)(Code)
Converts a byte array into a string. It assumes that 8-bits represents a byte. There should there for be one character per byte.
Parameters:
  in - byte[] to be converted Converted string



intoString16
public static String intoString16(byte[] in)(Code)
Converts a byte array into a string. It assumes that 16-bits represents a byte.
Parameters:
  in - byte[] to be converted Converted string



main
public static void main(String args)(Code)
This method can be used from the command line for creating a Secret Key.
Parameters:
  args - the command line argumentsRequires one mandatory parameter, which is the file name to use to write out the SecretKey



readKey
public static SecretKey readKey(File file) throws IOException, ClassNotFoundException(Code)
Read a file that should contain a serialized Secret key The secret key object
Parameters:
  file - The file object that points to the key file
throws:
  ClassNotFoundException - If the SecretKey class is not available
throws:
  IOException - If the specfied file can't be loaded



readKeyClassPath
public static SecretKey readKeyClassPath(String name) throws IOException, ClassNotFoundException(Code)
Read a file that should contain a serialized Secret key, the file is read as a resource on the classpath The secret key object
Parameters:
  name - The resource name that points to the key file
throws:
  ClassNotFoundException - If the SecretKey class is not available
throws:
  IOException - If the specfied file can't be loaded



toHex
public static char toHex(byte b)(Code)
Utility function to convert a number into a hex character. Takes the lowest 4 bits and converts it to a character '0'..'F'
Parameters:
  b - The byte to convert The Hex character



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.