author | Da Risk <da_risk@beem-project.com> |
Sun, 13 Jan 2013 20:11:53 +0100 | |
changeset 1015 | 63669480c941 |
child 1018 | 8daca77fabc1 |
permissions | -rw-r--r-- |
1015
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
1 |
/* |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, Isode Limited, London, England. |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
3 |
* All rights reserved. |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
4 |
*/ |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
5 |
/* |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
6 |
* Copyright (c) 2010, Remko Tron�on. |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
7 |
* All rights reserved. |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
8 |
*/ |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
9 |
package com.isode.stroke.stringcodecs; |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
10 |
|
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
11 |
import com.isode.stroke.base.ByteArray; |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
12 |
import java.security.MessageDigest; |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
13 |
import java.security.NoSuchAlgorithmException; |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
14 |
|
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
15 |
public class SHA1 { |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
16 |
|
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
17 |
public static ByteArray getHash(ByteArray data) { |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
18 |
MessageDigest md; |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
19 |
try { |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
20 |
md = MessageDigest.getInstance("SHA-1"); |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
21 |
} catch (NoSuchAlgorithmException ex) { |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
22 |
throw new IllegalStateException("JRE doesn't have an SHA hash function", ex); |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
23 |
} |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
24 |
md.update(data.getData()); |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
25 |
return new ByteArray(md.digest()); |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
26 |
} |
63669480c941
Add an implementation of the SCRAM-SHA-! SASL mechanism.
Da Risk <da_risk@beem-project.com>
parents:
diff
changeset
|
27 |
} |