Examples of Signature


Examples of java.security.Signature

   * @throws NoSuchAlgorithmException
   * @throws SignatureException
   * @throws InvalidKeyException
   */
  public void verifyExtension() throws NoSuchAlgorithmException, SignatureException, InvalidKeyException {
    Signature verificationEngine = Signature.getInstance(getSigningAlgorithm());
    signedExtension.verify(publicKey, verificationEngine);
    verified = true;
  }
View Full Code Here

Examples of java.security.Signature

                }

                signature = bar.readBinaryString();
            }

            Signature s = Signature.getInstance("SHA1withRSA");
            s.initVerify(pubKey);
            s.update(data);

            return s.verify(signature);
        } catch (NoSuchAlgorithmException nsae) {
            throw new InvalidSignatureException();
        } catch (IOException ioe) {
            throw new InvalidSignatureException();
        } catch (java.security.InvalidKeyException ike) {
View Full Code Here

Examples of java.security.Signature

     *
     * @return
     */
    public byte[] generateSignature(byte[] data) {
        try {
            Signature sig = Signature.getInstance("SHA1withRSA");
            sig.initSign(prvKey);
            sig.update(data);

            ByteArrayWriter baw = new ByteArrayWriter();
            baw.writeString(getAlgorithmName());
            baw.writeBinaryString(sig.sign());

            return baw.toByteArray();
        } catch (Exception e) {
            return null;
        }
View Full Code Here

Examples of java.security.Signature

                asn1s.length);
                         int soffset = (((signature[20] & 0x80) == 0x80) ? 1 : 0);
                         System.arraycopy(signature, 20, encoded,
                asn1r.length + roffset + 20 + asn1s.length + soffset, 20);
             */
            Signature sig = Signature.getInstance("SHA1withDSA");
            sig.initVerify(pubkey);
            sig.update(data);

            return sig.verify(encoded);
        } catch (NoSuchAlgorithmException nsae) {
            throw new InvalidSignatureException();
        } catch (java.security.InvalidKeyException ike) {
            throw new InvalidSignatureException();
        } catch (IOException ioe) {
View Full Code Here

Examples of java.security.Signature

     * @throws InvalidSshKeySignatureException
     */
    public byte[] generateSignature(byte[] data)
        throws InvalidSignatureException {
        try {
            Signature sig = Signature.getInstance("SHA1withDSA");
            sig.initSign(prvkey);

            sig.update(data);

            byte[] signature = sig.sign();
            byte[] decoded = new byte[40];
            SimpleASNReader asn = new SimpleASNReader(signature);
            asn.getByte();
            asn.getLength();
            asn.getByte();
View Full Code Here

Examples of java.security.Signature

      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();
         int count = 0;
         for (int i = 0; i < this.headers.size(); i++)
         {
            String name = this.headers.get(i);
            if (i > 0) headerCat.append(":");
            headerCat.append(name);
         }
         attributes.put(HEADERS, headerCat.toString());
         updateSignatureWithHeader(headers, signature);
      }

      String encodedBodyHash = calculateEncodedHash(body, hashAlgorithm);

      attributes.put(BODY_HASH, encodedBodyHash);

      StringBuffer dosetaBuffer = new StringBuffer();

      boolean first = true;
      for (Map.Entry<String, String> entry : attributes.entrySet())
      {
         if (first) first = false;
         else dosetaBuffer.append(";");

         dosetaBuffer.append(entry.getKey()).append("=").append(entry.getValue());
      }
      if (!first) dosetaBuffer.append(";");
      dosetaBuffer.append("b=");
      String dosetaHeader = dosetaBuffer.toString();
      signature.update(dosetaHeader.getBytes());

      byte[] signed = signature.sign();
      setSignature(signed);
      String base64Signature = Base64.encodeBytes(signed);
      dosetaHeader += base64Signature;
//      System.out.println("***: " + dosetaHeader);
      this.headerValue = dosetaHeader;
View Full Code Here

Examples of java.security.Signature

      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

Examples of java.security.Signature

            String algo = SOSSignature.hashAlgorithm + "With"
                    + privKey.getAlgorithm();

            /* Signature */
            Signature sign = Signature.getInstance(algo, SOSSignature.provider);

            /* initialis. mit prived key */
            sign.initSign(privKey);

            /* lesen aus fileToSign und update() */
            FileInputStream fis = new FileInputStream(fileToSign);
            BufferedInputStream bufin = new BufferedInputStream(fis);
            byte[] buffer = new byte[1024];
            int len;
            while (bufin.available() != 0) {
                len = bufin.read(buffer);
                sign.update(buffer, 0, len);
            }
            bufin.close();

            /* generate unterschrift */
            byte[] realSig = sign.sign();

            /* save in to file �signature� */
            saveToFile(realSig, signFile);
        } catch (NoClassDefFoundError e) {
            throw new Exception("no such Definition : " + e);
View Full Code Here

Examples of java.security.Signature

            }

            /*
             * Signature Objekt erzeugen mit mit public key verify
             */
            Signature sig = Signature.getInstance(SOSSignature.hashAlgorithm
                    + "With" + pubKey.getAlgorithm(), SOSSignature.provider);
            sig.initVerify(pubKey);

            /* lesen from file data update() */
            FileInputStream datafis = new FileInputStream(dataFile);
            BufferedInputStream bufin = new BufferedInputStream(datafis);
            byte[] buffer = new byte[1024];
            int len;
            while (bufin.available() != 0) {
                len = bufin.read(buffer);
                sig.update(buffer, 0, len);
            }
            bufin.close();

            /* verify */
            boolean verifies = sig.verify(sigToVerify);
            //System.out.println("Signature verifies: " + verifies);

            return verifies;

        } catch (NoClassDefFoundError e) {
View Full Code Here

Examples of java.security.Signature

      System.out.println("No signature for " + filename);
      return false;
    }
    try {

      Signature sig = Signature.getInstance("SHA1withRSA");
      sig.initVerify(ks.getCertificate(ClientGameConfiguration.get("UPDATE_CERT_NAME")).getPublicKey());

      FileInputStream datafis = new FileInputStream(filename);
      InputStream buf = new BufferedInputStream(datafis);

      byte[] temp = new byte[1024];
      int length = 0;
      while (buf.available() != 0) {
        length = buf.read(temp);
        sig.update(temp, 0, length);
      }
      buf.close();

      boolean isVaild = sig.verify(hexStringToByteArray(signature));
      System.out.println("Validated " + filename + ": " + isVaild);
      return isVaild;
    } catch (Exception e) {
      e.printStackTrace();
      return false;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.