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