Package java.security

Examples of java.security.SignatureException


            return cipher.processBlock(bytes, 0, bytes.length);
        }
        catch (ArrayIndexOutOfBoundsException e)
        {
            throw new SignatureException("key too small for signature type");
        }
        catch (Exception e)
        {
            throw new SignatureException(e.toString());
        }
    }
View Full Code Here


    sig.initVerify(key);
    sig.update(this.getTBSCertList());
    if ( !sig.verify(this.getSignature()) )
    {
      throw new SignatureException("CRL does not verify with supplied public key.");
    }
  }
View Full Code Here

            return derEncode(sig[0], sig[1]);
        }
        catch (Exception e)
        {
            throw new SignatureException(e.toString());
        }
    }
View Full Code Here

        {
            sig = derDecode(sigBytes);
        }
        catch (Exception e)
        {
            throw new SignatureException("error decoding signature bytes.");
        }

        return signer.verifySignature(hash, sig[0], sig[1]);
    }
View Full Code Here

   public void sign(Map headers, byte[] body, PrivateKey defaultKey) throws SignatureException
   {
      PrivateKey key = privateKey == null ? defaultKey : privateKey;
      if (key == null)
      {
         throw new SignatureException("private key is null, cannot sign");
      }
      attributes.put(VERSION, "1");
      attributes.put(ALGORITHM, SigningAlgorithm.SHA256withRSA.getRfcNotation());
      attributes.put(CANONICALIZATION, "simple/simple");
      String algorithm = SigningAlgorithm.SHA256withRSA.getJavaSecNotation();
      String hashAlgorithm = SigningAlgorithm.SHA256withRSA.getJavaHashNotation();

      if (getDomain() == null)
      {
         throw new SignatureException("You must have the domain attribute set on your signature header");
      }

      Signature signature = null;
      try
      {
         signature = Signature.getInstance(algorithm);
         signature.initSign(key);
      }
      catch (Exception e)
      {
         throw new SignatureException(e);
      }

      if (this.headers.size() > 0)
      {
         StringBuffer headerCat = new StringBuffer();
View Full Code Here

      {
         digest = MessageDigest.getInstance(hashAlgorithm);
      }
      catch (Exception e)
      {
         throw new SignatureException(e);
      }

      int length = body.length;

      if (attributes.containsKey(LENGTH))
View Full Code Here

         count.put(name, index);

         Object v = transmittedHeaders.get(name);
         if (v == null)
         {
            throw new SignatureException("Unable to find header " + name + (index > 0 ? "[" + index + "]" : "") + " to sign header with");
         }

         if (v instanceof List)
         {
            List l = (List) v;
            int i = l.size() - 1 - index;
            if (i < 0)
            {
               throw new SignatureException("Unable to find header " + name + (index > 0 ? "[" + index + "]" : "") + " to sign header with");
            }
            v = l.get(i);
         }
         else if (index > 0)
         {
            throw new SignatureException("Unable to find header " + name + (index > 0 ? "[" + index + "]" : "") + " to sign header with");
         }
         String entry = name + ":" + v.toString() + "\r\n";
         signature.update(entry.getBytes());
      }
   }
View Full Code Here

   public void verify(Map headers, byte[] body, PublicKey key) throws SignatureException
   {
      String algorithm = getAlgorithm();
      if (algorithm == null || !SigningAlgorithm.SHA256withRSA.getRfcNotation().toLowerCase().equals(algorithm.toLowerCase()))
      {
         throw new SignatureException("Unsupported algorithm " + algorithm);
      }

      Signature verifier = null;
      try
      {
         verifier = Signature.getInstance(SigningAlgorithm.SHA256withRSA.getJavaSecNotation());
         verifier.initVerify(key);
      }
      catch (Exception e)
      {
         throw new SignatureException(e);
      }


      String encodedBh = attributes.get("bh");
      if (encodedBh == null)
      {
         throw new SignatureException("There was no body hash (bh) in header");
      }

      byte[] bh = hash(body, SigningAlgorithm.SHA256withRSA.getJavaHashNotation());
      byte[] enclosedBh = null;
      try
      {
         enclosedBh = Base64.decode(encodedBh);
      }
      catch (IOException e)
      {
         throw new SignatureException("Failed to parse body hash (bh)", e);
      }

      if (Arrays.equals(bh, enclosedBh) == false)
      {
         throw new SignatureException("Body hashes do not match.");
      }
      updateSignatureWithHeader(headers, verifier);
      ParameterParser parser = new ParameterParser();
      String strippedHeader = parser.setAttribute(headerValue.toCharArray(), 0, headerValue.length(), ';', "b", "");
      verifier.update(strippedHeader.getBytes());
      if (verifier.verify(getSignature()) == false)
      {
         throw new SignatureException("Failed to verify signature.");
      }
   }
View Full Code Here

         {
            key = repository.findPublicKey(signature);
         }
         if (key == null)
         {
            throw new SignatureException("Could not find PublicKey for DKIMSignature " + signature);
         }
      }

      signature.verify(headers, body, key);
      if (verification.isIgnoreExpiration() == false)
      {
         if (signature.isExpired())
         {
            throw new SignatureException("Signature expired");
         }
      }
      if (verification.isStaleCheck())
      {
         if (signature.isStale(verification.getStaleSeconds(),
                 verification.getStaleMinutes(),
                 verification.getStaleHours(),
                 verification.getStaleDays(),
                 verification.getStaleMonths(),
                 verification.getStaleYears()))
         {
            throw new SignatureException("Signature is stale");
         }
      }
   }
View Full Code Here

            {
                sigParams.init(params.toASN1Primitive().getEncoded());
            }
            catch (IOException e)
            {
                throw new SignatureException("IOException decoding parameters: " + e.getMessage());
            }
           
            if (signature.getAlgorithm().endsWith("MGF1"))
            {
                try
                {
                    signature.setParameter(sigParams.getParameterSpec(PSSParameterSpec.class));
                }
                catch (GeneralSecurityException e)
                {
                    throw new SignatureException("Exception extracting parameters: " + e.getMessage());
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of java.security.SignatureException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.