Package java.security

Examples of java.security.SecureRandom


                db.createTable(T_DDL);
                return true;
            }
        });

        final SecureRandom rnd = new SecureRandom();
        final ISqlJetTable t = db.getTable("t");
        final byte[] blob = new byte[1024 + 4096];

        rnd.nextBytes(blob);

        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {

                try {
                    t.insert(rnd.nextInt(2048), blob);
                } catch (SqlJetException e) {
                    if (!SqlJetErrorCode.CONSTRAINT.equals(e.getErrorCode())) {
                        throw e;
                    }
                }
View Full Code Here


                db.createTable(T_DDL);
                return true;
            }
        });

        final SecureRandom rnd = new SecureRandom();
        final ISqlJetTable t = db.getTable("t");
        final byte[] blob = new byte[1024 + 4096];

        rnd.nextBytes(blob);

        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {

                try {
                    t.insert(rnd.nextInt(2048), blob);
                } catch (SqlJetException e) {
                    if (!SqlJetErrorCode.CONSTRAINT.equals(e.getErrorCode())) {
                        throw e;
                    }
                }

                return true;
            }
        });

        db.runWriteTransaction(new ISqlJetTransaction() {
            public Object run(SqlJetDb db) throws SqlJetException {
                final ISqlJetCursor c = t.open();
                try {
                    if (!c.eof()) {
                        do {
                            rnd.nextBytes(blob);

                            try {
                                c.update(rnd.nextInt(2048), blob);
                            } catch (SqlJetException e) {
                                if (!SqlJetErrorCode.CONSTRAINT.equals(e.getErrorCode())) {
                                    throw e;
                                }
                            }
View Full Code Here

   
        final SqlJetException misuse = new SqlJetException(SqlJetErrorCode.MISUSE);
       
        EasyMock.expect( fileSystem.randomness(EasyMock.anyInt()) ).andStubAnswer(
                new IAnswer<byte[]>() {
                    final SecureRandom random = new SecureRandom();
                    public byte[] answer() throws Throwable {
                        final Object[] args = EasyMock.getCurrentArguments();
                        if(null==args||0==args.length) throw misuse;
                        final Object arg = args[0];
                        if(null==argthrow misuse;
                        if( arg instanceof Integer ){
                            final Integer numBytes = (Integer) arg;
                            if( 0>=numBytes ) throw misuse;
                            final byte[] bytes = new byte[numBytes];
                            random.nextBytes(bytes);
                            return bytes;
                        } else throw misuse;
                    }
                }
            );
View Full Code Here

        db.beginTransaction(SqlJetTransactionMode.WRITE);
        db.createTable(TABLE_DDL);
        db.createIndex(INDEX_DDL);
        db.commit();

        SecureRandom rnd = new SecureRandom();
        ISqlJetTable table = db.getTable("tiles");
        for (int i = 0; i < INSERTS_COUNT; i++) {
            byte[] blob = new byte[1024 + rnd.nextInt(4096)];
            rnd.nextBytes(blob);

            int x = rnd.nextInt(2048);
            int y = 0;
            int zoom = 10;
            db.beginTransaction(SqlJetTransactionMode.WRITE);
            try {
                table.insert(x, y, zoom, 0, blob);
View Full Code Here

    TrustManagerFactory trustManagerFactory = TrustManagerFactory
        .getInstance(_sslTrustManagerFactoryAlgorithm);
    trustManagerFactory.init(trustStore);
    trustManagers = trustManagerFactory.getTrustManagers();

    SecureRandom secureRandom = _secureRandomAlgorithm == null ? null : SecureRandom
        .getInstance(_secureRandomAlgorithm);

    SSLContext context = _provider == null ? SSLContext.getInstance(SipConnectors.TLS) : SSLContext
        .getInstance(SipConnectors.TLS, _provider);
View Full Code Here

    {
        DataOutputStream dos = null;
        DataInputStream  dis = null;
        try
        {
            SecureRandom srand = new SecureRandom();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            dos = new DataOutputStream( baos );
            try
            {
                dos.write( InetAddress.getLocalHost().getAddress() );
            }
            catch (Exception e)
            {
                if (logger.isLoggable(MLevel.INFO))
                    logger.log(MLevel.INFO, "Failed to get local InetAddress for VMID. This is unlikely to matter. At all. We'll add some extra randomness", e);
                dos.write( srand.nextInt() );
            }
            dos.writeLong(System.currentTimeMillis());
            dos.write( srand.nextInt() );
           
            int remainder = baos.size() % 4; //if it wasn't a 4 byte inet address
            if (remainder > 0)
            {
                int pad = 4 - remainder;
                byte[] pad_bytes = new byte[pad];
                srand.nextBytes(pad_bytes);
                dos.write(pad_bytes);
            }
           
            StringBuffer sb = new StringBuffer(32);
            byte[] vmid_bytes = baos.toByteArray();
View Full Code Here

         keyStore.load(null, null);
         keyStore.setKeyEntry("dummy alias", privateKey, null, (Certificate[]) certs.toArray(new Certificate[0]));
         kmf.init(keyStore, null);

         SSLContext sc = SSLContext.getInstance("TLS");
         sc.init(kmf.getKeyManagers(), trustManager, new SecureRandom());
         return sc;
      } catch (GeneralSecurityException e) {
         throw propagate(e);
      } catch (IOException e) {
         throw propagate(e);
View Full Code Here

            a = transformation;
        }
        Cipher enccipher = null;
        try {
            KeyGenerator keygen = KeyGenerator.getInstance(a);
            keygen.init(new SecureRandom());
            key = keygen.generateKey();
            enccipher = Cipher.getInstance(transformation);
            enccipher.init(Cipher.ENCRYPT_MODE, key);
            ivp = enccipher.getIV();
        } catch (GeneralSecurityException e) {
View Full Code Here

    return retval;
  }

  public SecureRandom getSecureRandom() {
    return new SecureRandom(mainIV);
  }
View Full Code Here

        return cipher.doFinal(inpBytes);
    }

    public static KeyPair generateKeyPair() throws NoSuchAlgorithmException {
        KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
        kpg.initialize(2048, new SecureRandom());

        return kpg.generateKeyPair();
    }
View Full Code Here

TOP

Related Classes of java.security.SecureRandom

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.