author | Jaroslav Tulach <jtulach@netbeans.org> |
Sat, 14 Jun 2008 09:52:23 +0200 | |
changeset 44 | 716af5f2ebd1 |
permissions | -rw-r--r-- |
jtulach@44 | 1 |
/* |
jtulach@44 | 2 |
* To change this template, choose Tools | Templates |
jtulach@44 | 3 |
* and open the template in the editor. |
jtulach@44 | 4 |
*/ |
jtulach@44 | 5 |
|
jtulach@44 | 6 |
package org.apidesign.impl.security.extension; |
jtulach@44 | 7 |
|
jtulach@44 | 8 |
import org.apidesign.impl.security.friendapi.DigestImplementation; |
jtulach@44 | 9 |
import org.apidesign.impl.security.friendapi.DigestProvider; |
jtulach@44 | 10 |
import java.nio.ByteBuffer; |
jtulach@44 | 11 |
import java.security.MessageDigest; |
jtulach@44 | 12 |
import java.security.NoSuchAlgorithmException; |
jtulach@44 | 13 |
import java.util.logging.Level; |
jtulach@44 | 14 |
import java.util.logging.Logger; |
jtulach@44 | 15 |
|
jtulach@44 | 16 |
/** |
jtulach@44 | 17 |
* |
jtulach@44 | 18 |
* @author Jaroslav Tulach <jaroslav.tulach@apidesign.org> |
jtulach@44 | 19 |
*/ |
jtulach@44 | 20 |
public class BridgeToOldAlgorithmsProvider implements DigestProvider { |
jtulach@44 | 21 |
|
jtulach@44 | 22 |
public DigestImplementation create(String algorithm) { |
jtulach@44 | 23 |
try { |
jtulach@44 | 24 |
final MessageDigest md = MessageDigest.getInstance(algorithm); |
jtulach@44 | 25 |
return new DigestImplementation(algorithm) { |
jtulach@44 | 26 |
|
jtulach@44 | 27 |
@Override |
jtulach@44 | 28 |
public void update(ByteBuffer bb) { |
jtulach@44 | 29 |
md.update(bb); |
jtulach@44 | 30 |
} |
jtulach@44 | 31 |
|
jtulach@44 | 32 |
@Override |
jtulach@44 | 33 |
public byte[] digest() { |
jtulach@44 | 34 |
return md.digest(); |
jtulach@44 | 35 |
} |
jtulach@44 | 36 |
}; |
jtulach@44 | 37 |
} catch (NoSuchAlgorithmException ex) { |
jtulach@44 | 38 |
Logger.getLogger(BridgeToOldAlgorithmsProvider.class.getName()).log(Level.INFO, null, ex); |
jtulach@44 | 39 |
return null; |
jtulach@44 | 40 |
} |
jtulach@44 | 41 |
} |
jtulach@44 | 42 |
|
jtulach@44 | 43 |
static { |
jtulach@44 | 44 |
new BridgeToOld(); |
jtulach@44 | 45 |
} |
jtulach@44 | 46 |
} |