| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.core.api.util; |
| 17 | |
|
| 18 | |
import org.apache.commons.codec.binary.Base64; |
| 19 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
| 20 | |
|
| 21 | |
import java.io.ByteArrayOutputStream; |
| 22 | |
import java.io.IOException; |
| 23 | |
import java.io.ObjectOutput; |
| 24 | |
import java.io.ObjectOutputStream; |
| 25 | |
import java.io.UnsupportedEncodingException; |
| 26 | |
import java.security.GeneralSecurityException; |
| 27 | |
import java.security.MessageDigest; |
| 28 | |
|
| 29 | |
|
| 30 | |
|
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
public final class ChecksumUtils { |
| 35 | |
|
| 36 | |
|
| 37 | |
|
| 38 | |
|
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public static String calculateChecksum(Object object) { |
| 44 | 0 | ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
| 45 | 0 | ObjectOutput out = null; |
| 46 | |
try { |
| 47 | 0 | out = new ObjectOutputStream(bos); |
| 48 | 0 | out.writeObject(object); |
| 49 | 0 | } catch (IOException e) { |
| 50 | 0 | throw new RiceRuntimeException(e); |
| 51 | |
} finally { |
| 52 | 0 | try { |
| 53 | 0 | out.close(); |
| 54 | 0 | } catch (IOException e) {} |
| 55 | 0 | } |
| 56 | |
try { |
| 57 | 0 | MessageDigest md = MessageDigest.getInstance("SHA-1"); |
| 58 | 0 | return new String( Base64.encodeBase64(md.digest(bos.toByteArray())), "UTF-8"); |
| 59 | 0 | } catch( GeneralSecurityException ex ) { |
| 60 | 0 | throw new RiceRuntimeException(ex); |
| 61 | 0 | } catch( UnsupportedEncodingException ex ) { |
| 62 | 0 | throw new RiceRuntimeException(ex); |
| 63 | |
} |
| 64 | |
} |
| 65 | |
|
| 66 | |
@SuppressWarnings("unused") |
| 67 | 0 | private ChecksumUtils() { |
| 68 | 0 | throw new UnsupportedOperationException("Should never be executed."); |
| 69 | |
} |
| 70 | |
|
| 71 | |
} |