All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jcp.xml.dsig.internal.dom.DOMSHA1DigestMethod Maven / Gradle / Ivy

The newest version!
/*    */ package org.jcp.xml.dsig.internal.dom;
/*    */ 
/*    */ import java.io.IOException;
/*    */ import java.io.InputStream;
/*    */ import java.security.DigestException;
/*    */ import java.security.DigestInputStream;
/*    */ import java.security.InvalidAlgorithmParameterException;
/*    */ import java.security.MessageDigest;
/*    */ import java.security.NoSuchAlgorithmException;
/*    */ import java.security.spec.AlgorithmParameterSpec;
/*    */ import java.util.logging.Level;
/*    */ import java.util.logging.Logger;
/*    */ import javax.xml.crypto.MarshalException;
/*    */ import javax.xml.crypto.dsig.spec.DigestMethodParameterSpec;
/*    */ import org.w3c.dom.Element;
/*    */ 
/*    */ public final class DOMSHA1DigestMethod extends DOMDigestMethod
/*    */ {
/* 32 */   private static Logger log = Logger.getLogger("org.jcp.xml.dsig.internal.dom");
/*    */   private MessageDigest md;
/*    */ 
/*    */   public DOMSHA1DigestMethod(AlgorithmParameterSpec params)
/*    */     throws InvalidAlgorithmParameterException
/*    */   {
/* 40 */     super("http://www.w3.org/2000/09/xmldsig#sha1", params);
/*    */   }
/*    */ 
/*    */   public DOMSHA1DigestMethod(Element dmElem)
/*    */     throws MarshalException
/*    */   {
/* 49 */     super(dmElem);
/*    */   }
/*    */ 
/*    */   protected void checkParams(DigestMethodParameterSpec params) throws InvalidAlgorithmParameterException
/*    */   {
/* 54 */     if (params != null)
/* 55 */       throw new InvalidAlgorithmParameterException("no parameters should be specified for SHA1 message digest algorithm");
/*    */   }
/*    */ 
/*    */   protected DigestMethodParameterSpec unmarshalParams(Element paramsElem)
/*    */     throws MarshalException
/*    */   {
/* 62 */     throw new MarshalException("no parameters should be specified for SHA1 message digest algorithm");
/*    */   }
/*    */ 
/*    */   protected void marshalParams(Element parent, String dsPrefix)
/*    */     throws MarshalException
/*    */   {
/* 69 */     throw new MarshalException("no parameters should be specified for SHA1 message digest algorithm");
/*    */   }
/*    */ 
/*    */   public byte[] digest(InputStream is) throws IOException, DigestException
/*    */   {
/* 74 */     if (is == null)
/* 75 */       throw new NullPointerException("pre-digested input stream is null");
/*    */     try
/*    */     {
/* 78 */       this.md = MessageDigest.getInstance("SHA");
/*    */     } catch (NoSuchAlgorithmException nsae) {
/* 80 */       throw new DigestException("SHA1 MessageDigest not available");
/*    */     }
/* 82 */     DigestInputStream dis = new DigestInputStream(is, this.md);
/* 83 */     if (log.isLoggable(Level.FINE)) {
/* 84 */       log.log(Level.FINE, "Predigested reference:\n");
/* 85 */       byte[] buf = new byte[1024];
/* 86 */       int bytesRead = 0;
/*    */       while (true) {
/* 88 */         int read = dis.read(buf);
/* 89 */         if (read == -1) {
/*    */           break;
/*    */         }
/* 92 */         bytesRead += read;
/* 93 */         log.log(Level.FINE, new String(buf));
/*    */       }
/* 95 */       log.log(Level.FINE, "bytesRead=" + bytesRead);
/*    */     }
/* 97 */     return this.md.digest();
/*    */   }
/*    */ }

/* Location:           E:\HYN\Java\trunk\ref\lib-dep\xmldsig\xmldsig.jar
 * Qualified Name:     org.jcp.xml.dsig.internal.dom.DOMSHA1DigestMethod
 * JD-Core Version:    0.6.2
 */




© 2015 - 2024 Weber Informatics LLC | Privacy Policy