Package java.security

Examples of java.security.SecureRandom$StrongPatternHolder


   * @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


   * @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

   * @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

            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

            // 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

     * 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

    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

     *
     * @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

            byte[]  d = new byte[16];
            byte[]  e = new byte[16];

            if (random == null)
            {
                random = new SecureRandom();
            }

            random.nextBytes(d);
            random.nextBytes(e);
View Full Code Here

    // System.out.println( "get( " + keys + ") " + this );

    try{
      putInt( buffer, VERSION, 255 );
           
      SecureRandom random = SecureRandom.getInstance("SHA1PRNG");

      Signature sig = CryptoECCUtils.getSignature(myPrivateKey);
     
      if ( keys ){
               
        final byte[] rawMyPubkey = CryptoECCUtils.keyToRawdata(myPublicKey);
       
        final byte[] rawEphemeralPubkey = CryptoECCUtils.keyToRawdata(ephemeralKeyPair.getPublic());
       
        sig.update(rawMyPubkey);
         
        sig.update(rawEphemeralPubkey);
         
        final byte[] rawSign = sig.sign();
       
        final byte[] pad = new byte[random.nextInt(32)];
       
        random.nextBytes(pad);
       
        putBytes( buffer, rawMyPubkey, 65535 );
       
        putBytes( buffer, rawEphemeralPubkey, 65535 );
       
        putBytes( buffer, rawSign, 65535 );
       
        putBytes( buffer, pad, 65535 );
 
      }else{
         
        if ( sharedSecret == null ){
         
          throw( new CryptoManagerException( "phase error: keys not received" ));
        }
       
        final byte[] IV = new byte[20 + random.nextInt(32)];
       
        random.nextBytes(IV);

        sig.update(IV);
       
        sig.update(sharedSecret);
       
View Full Code Here

TOP

Related Classes of java.security.SecureRandom$StrongPatternHolder

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.