Examples of SecureRandom


Examples of java.security.SecureRandom

    keepAliveHdrParams = "timeout=" + timeoutKeepAliveSec + ", max="
        + maxAliveConnUse;

    expiredIn = arguments.get(ARG_SESSION_TIMEOUT) != null ? ((Integer) arguments
        .get(ARG_SESSION_TIMEOUT)).intValue() : DEF_SESSION_TIMEOUT;
    srandom = new SecureRandom(
        (arguments.get(ARG_SESSION_SEED) == null ? "TJWS" + new Date()
            : (String) arguments.get(ARG_SESSION_SEED)).getBytes());
    try {
      gzipInStreamConstr = Class.forName("java.util.zip.GZIPInputStream")
          .getConstructor(new Class[] { InputStream.class });
View Full Code Here

Examples of java.security.SecureRandom

   * @throws Exception
   */
  public static byte[] encrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
View Full Code Here

Examples of java.security.SecureRandom

   * @throws Exception
   */
  public static byte[] decrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
View Full Code Here

Examples of java.security.SecureRandom

   * @throws Exception
   */
  public static byte[] encrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpecת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
View Full Code Here

Examples of java.security.SecureRandom

   * @throws Exception
   */
  public static byte[] decrypt(byte[] src, byte[] key)
    throws Exception {
    //    DES�㷨Ҫ����һ�������ε������Դ
    SecureRandom sr = new SecureRandom();
    // ��ԭʼ�ܳ����ݴ���һ��DESKeySpec����
    DESKeySpec dks = new DESKeySpec(key);
    // ����һ���ܳ׹�����Ȼ��������DESKeySpec����ת����
    // һ��SecretKey����
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(DES);
View Full Code Here

Examples of java.security.SecureRandom

            throw new IOException("Could not delete " + file.getAbsolutePath());
        }
    }

    private static void testLoop() throws Exception {
        Random random = new SecureRandom();
        while (true) {
            runOneTest(random.nextInt());
        }
    }
View Full Code Here

Examples of java.security.SecureRandom

            // In this case it is initialized using our own seed implementation
            // and afterwards (in the thread) using the regular algorithm.
            Runnable runnable = new Runnable() {
                public void run() {
                    try {
                        SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
                        byte[] seed = sr.generateSeed(20);
                        synchronized (cachedSecureRandom) {
                            cachedSecureRandom.setSeed(seed);
                            seeded = true;
                        }
                    } catch (Exception e) {
                        // NoSuchAlgorithmException
                        warn("SecureRandom", e);
                    }
                }
            };

            try {
                Thread t = new Thread(runnable);
                // let the process terminate even if generating the seed is really slow
                t.setDaemon(true);
                t.start();
                Thread.yield();
                try {
                    // normally, generateSeed takes less than 200 ms
                    t.join(400);
                } catch (InterruptedException e) {
                    warn("InterruptedException", e);
                }
                if (!seeded) {
                    byte[] seed = generateAlternativeSeed();
                    // this never reduces randomness
                    synchronized (cachedSecureRandom) {
                        cachedSecureRandom.setSeed(seed);
                    }
                }
            } catch (SecurityException e) {
                // workaround for the Google App Engine: don't use a thread
                runnable.run();
                generateAlternativeSeed();
            }

        } catch (Exception e) {
            // NoSuchAlgorithmException
            warn("SecureRandom", e);
            cachedSecureRandom = new SecureRandom();
        }
        return cachedSecureRandom;
    }
View Full Code Here

Examples of java.security.SecureRandom

     * Get a cryptographically secure pseudo random long value.
     *
     * @return the random long value
     */
    public static long secureRandomLong() {
        SecureRandom sr = getSecureRandom();
        synchronized (sr) {
            return sr.nextLong();
        }
    }
View Full Code Here

Examples of java.security.SecureRandom

    public static byte[] secureRandomBytes(int len) {
        if (len <= 0) {
            len = 1;
        }
        byte[] buff = new byte[len];
        SecureRandom sr = getSecureRandom();
        synchronized (sr) {
            sr.nextBytes(buff);
        }
        return buff;
    }
View Full Code Here

Examples of java.security.SecureRandom

     *
     * @param lowerThan the value returned will be lower than this value
     * @return the random long value
     */
    public static int secureRandomInt(int lowerThan) {
        SecureRandom sr = getSecureRandom();
        synchronized (sr) {
            return sr.nextInt(lowerThan);
        }
    }
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.