removed singleton pattern and renamed class
authorFelix Schumacher <felix.schumacher@internetallee.de>
Tue, 24 Aug 2010 18:32:20 +0000 (20:32 +0200)
committerFelix Schumacher <felix.schumacher@internetallee.de>
Tue, 24 Aug 2010 18:32:20 +0000 (20:32 +0200)
src/org/mcb/services/PasswordService.java [new file with mode: 0644]

diff --git a/src/org/mcb/services/PasswordService.java b/src/org/mcb/services/PasswordService.java
new file mode 100644 (file)
index 0000000..e5f0da7
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+
+package org.mcb.services;
+
+/**
+ * 
+ * @author yawar.saeed
+ */
+
+import java.io.UnsupportedEncodingException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+
+import sun.misc.BASE64Encoder;
+
+public final class PasswordService {
+       
+       public synchronized String encrypt(String plaintext) throws Exception {
+               MessageDigest md = null;
+               try {
+                       md = MessageDigest.getInstance("SHA"); // step 2
+               } catch (NoSuchAlgorithmException e) {
+                       throw new Exception(e.getMessage());
+               }
+               try {
+                       md.update(plaintext.getBytes("UTF-8")); // step 3
+               } catch (UnsupportedEncodingException e) {
+                       throw new Exception(e.getMessage());
+               }
+               byte raw[] = md.digest(); // step 4
+               String hash = (new BASE64Encoder()).encode(raw); // step 5
+               return hash; // step 6
+       }
+
+}