EMMA Coverage Report (generated Tue Feb 12 22:23:49 ICT 2008)
[all classes][net.sourceforge.hiveutils.util]

COVERAGE SUMMARY FOR SOURCE FILE [PasswordEncryption.java]

nameclass, %method, %block, %line, %
PasswordEncryption.java0%   (0/1)0%   (0/3)0%   (0/40)0%   (0/13)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PasswordEncryption0%   (0/1)0%   (0/3)0%   (0/40)0%   (0/13)
<static initializer> 0%   (0/1)0%   (0/4)0%   (0/1)
PasswordEncryption (): void 0%   (0/1)0%   (0/3)0%   (0/2)
encrypt (String): String 0%   (0/1)0%   (0/33)0%   (0/10)

1//  Copyright 2004-2007 Jean-Francois Poilpret
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14 
15package net.sourceforge.hiveutils.util;
16 
17import java.security.MessageDigest;
18 
19import org.apache.commons.codec.binary.Base64;
20import org.apache.commons.logging.Log;
21import org.apache.commons.logging.LogFactory;
22import org.apache.hivemind.ApplicationRuntimeException;
23 
24final public class PasswordEncryption
25{
26        static final private Log        _logger = LogFactory.getLog(PasswordEncryption.class);
27 
28        private PasswordEncryption()
29        {
30        }
31        
32        //#### does MessageDigest.getInstance() return a new (thread-safe) instance
33        // every time???? This point is not clear in the API.
34//        static synchronized public String        encrypt(String plaintext)
35        //CSOFF: IllegalCatchCheck
36        static public String        encrypt(String str)
37        {
38                if (str == null)
39                {
40                        return str;
41                }
42                try
43                {
44                        MessageDigest md = MessageDigest.getInstance("SHA-1");
45                        md.update(str.getBytes("UTF-8"));
46                        byte[] raw = md.digest();
47                        byte[] b64str = Base64.encodeBase64(raw);
48                        return new String(b64str);
49                }
50                catch (Exception e)
51                {
52                        _logger.error("encrypt()", e);
53                        throw new ApplicationRuntimeException(e);
54                }
55        }
56        //CSON: IllegalCatchCheck
57}

[all classes][net.sourceforge.hiveutils.util]
EMMA 2.0.5312 (C) Vladimir Roubtsov