Package java.security

Examples of java.security.Signature$SignatureImpl


    int      version,
    int      size )
 
    throws Exception
  {
    Signature signature = CryptoECCUtils.getSignature( CryptoECCUtils.rawdataToPrivkey( private_key ));
   
    // key for signature is hash + version + size so we have some
    // control over auto-update process and prevent people from injecting
    // potentially huge bogus updates
 
    signature.update( encode( hash, version, size ));

    return( signature.sign());
  }
View Full Code Here


    int      version,
    int      size,
    byte[]    sig )
  {
    try{
      Signature signature = CryptoECCUtils.getSignature( CryptoECCUtils.rawdataToPubkey( public_key ));
 
      signature.update( encode( hash, version, size ));
 
      return( signature.verify( sig ));
     
    }catch( Throwable e ){
     
      Debug.out( e );
     
View Full Code Here

     
      return( false );
    }
   
    try{
      Signature  verifier = Signature.getInstance("MD5withRSA" );
     
      verifier.initVerify( key_block_public_key );
     
      verifier.update( kb.getRequest() );

      if ( !verifier.verify( kb.getCertificate())){
     
        log.log( "KB: request verify failed for " + DHTLog.getString2( kb.getKey()));

        filter.add( id );
       
View Full Code Here

  verifyKeyBlock(
    byte[]    request,
    byte[]    signature )
  {
    try{
      Signature  verifier = Signature.getInstance("MD5withRSA" );
     
      verifier.initVerify( key_block_public_key );
     
      verifier.update( request );

      if ( !verifier.verify( signature )){
     
        return( false );
      }
     
      return( true );
View Full Code Here

            req[6] = (byte)(time>>8);
            req[7] = (byte)(time);
           
            System.arraycopy( new SHA1Simple().calculateHash(key_block.getBytes()), 0, req, 8, 20 );
           
            Signature  sig = Signature.getInstance("MD5withRSA" );
           
            sig.initSign( key );
           
            sig.update( req );
           
            dhts[1].getTransport().getLocalContact().sendKeyBlock(
              new DHTTransportReplyHandlerAdapter()
              {
                public void
                keyBlockReply(
                  DHTTransportContact   _contact )
                {
                  System.out.println( "key block sent ok" );
                }
               
                public void
                failed(
                  DHTTransportContact   contact,
                  Throwable        error )
                {
                  System.out.println( "key block failed" );
                 
                  error.printStackTrace();
                }
              },
              req,
              sig.sign());
           
          }else{
           
            usage();
          }
View Full Code Here

     
      parameters.put( "public_key", pk_str );
    }
   
    try{
      Signature sig = CryptoECCUtils.getSignature( CryptoECCUtils.rawdataToPrivkey( private_key ));

      sig.update( ( name + pk_str + sid_str + version + content ).getBytes( "UTF-8" ));
     
      byte[]  sig_bytes = sig.sign();
     
      /*
      Signature verify = CryptoECCUtils.getSignature( CryptoECCUtils.rawdataToPubkey( public_key ));

      verify.update( ( name + pk_str + sid_str + version + content ).getBytes( "UTF-8" ));
View Full Code Here

        catch (IOException e)
        {
            throw new IllegalArgumentException("can't encode public key");
        }

        Signature sig = null;
       
        try
        {
            sig = Signature.getInstance(sigAlgId.getObjectId().getId(), provider);
        }
        catch (NoSuchAlgorithmException e)
        {
            sig = Signature.getInstance(signatureAlgorithm, provider);
        }

        sig.initSign(signingKey);

        try
        {
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            DEROutputStream         dOut = new DEROutputStream(bOut);

            dOut.writeObject(reqInfo);

            sig.update(bOut.toByteArray());
        }
        catch (Exception e)
        {
            throw new SecurityException("exception encoding TBS cert request - " + e);
        }

        this.sigBits = new DERBitString(sig.sign());
    }
View Full Code Here

    public boolean verify(
        String provider)
        throws NoSuchAlgorithmException, NoSuchProviderException,
                InvalidKeyException, SignatureException
    {
        Signature   sig = null;

        try
        {
            sig = Signature.getInstance(sigAlgId.getObjectId().getId(), provider);
        }
        catch (NoSuchAlgorithmException e)
        {
            //
            // try an alternate
            //
            if (oids.get(sigAlgId.getObjectId().getId()) != null)
            {
                String  signatureAlgorithm = (String)oids.get(sigAlgId.getObjectId().getId());

                sig = Signature.getInstance(signatureAlgorithm, provider);
            }
        }

        sig.initVerify(this.getPublicKey(provider));

        try
        {
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            DEROutputStream         dOut = new DEROutputStream(bOut);

            dOut.writeObject(reqInfo);

            sig.update(bOut.toByteArray());
        }
        catch (Exception e)
        {
            throw new SecurityException("exception encoding TBS cert request - " + e);
        }

        return sig.verify(sigBits.getBytes());
    }
View Full Code Here

        PrivateKey      key,
        String          provider,
        SecureRandom    random)
        throws NoSuchProviderException, SecurityException, SignatureException, InvalidKeyException
    {
        Signature sig = null;

        try
        {
            sig = Signature.getInstance(sigOID.getId(), provider);
        }
        catch (NoSuchAlgorithmException ex)
        {
            try
            {
                sig = Signature.getInstance(signatureAlgorithm, provider);
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new SecurityException("exception creating signature: " + e.toString());
            }
        }

        if (random != null)
        {
            sig.initSign(key, random);
        }
        else
        {
            sig.initSign(key);
        }

        TBSCertificateStructure tbsCert = tbsGen.generateTBSCertificate();

        try
        {
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            DEROutputStream         dOut = new DEROutputStream(bOut);

            dOut.writeObject(tbsCert);

            sig.update(bOut.toByteArray());
        }
        catch (Exception e)
        {
            throw new SecurityException("exception encoding TBS cert - " + e);
        }

        ASN1EncodableVector  v = new ASN1EncodableVector();

        v.add(tbsCert);
        v.add(sigAlgId);
        v.add(new DERBitString(sig.sign()));

        return new X509CertificateObject(new X509CertificateStructure(new DERSequence(v)));
    }
View Full Code Here

        PrivateKey      key,
        String          provider,
        SecureRandom    random)
        throws NoSuchProviderException, SecurityException, SignatureException, InvalidKeyException
    {
        Signature sig = null;

        try
        {
            sig = Signature.getInstance(sigOID.getId(), provider);
        }
        catch (NoSuchAlgorithmException ex)
        {
            try
            {
                sig = Signature.getInstance(signatureAlgorithm, provider);
            }
            catch (NoSuchAlgorithmException e)
            {
                throw new SecurityException("exception creating signature: " + e.toString());
            }
        }

        if (random != null)
        {
            sig.initSign(key, random);
        }
        else
        {
            sig.initSign(key);
        }

        if (extensions != null)
        {
            tbsGen.setExtensions(new X509Extensions(extOrdering, extensions));
        }

        TBSCertList tbsCrl = tbsGen.generateTBSCertList();

        try
        {
            ByteArrayOutputStream   bOut = new ByteArrayOutputStream();
            DEROutputStream         dOut = new DEROutputStream(bOut);

            dOut.writeObject(tbsCrl);

            sig.update(bOut.toByteArray());
        }
        catch (Exception e)
        {
            throw new SecurityException("exception encoding TBS cert - " + e);
        }

        // Construct the CRL
        ASN1EncodableVector  v = new ASN1EncodableVector();

        v.add(tbsCrl);
        v.add(sigAlgId);
        v.add(new DERBitString(sig.sign()));

        return new X509CRLObject(new CertificateList(new DERSequence(v)));
    }
View Full Code Here

TOP

Related Classes of java.security.Signature$SignatureImpl

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.