Search in sources :

Example 76 with SecureRandom

use of java.security.SecureRandom in project robovm by robovm.

the class myKeyGenerator method testInitKey.

/*
     * Test for <code>init(int keysize)</code> and
     * <code>init(int keysize, SecureRandom random)</code> methods
     * Assertion: throws InvalidParameterException if keysize is wrong
     *
     */
public void testInitKey() throws Exception {
    byte flag = 0xF;
    if (!DEFSupported) {
        fail(NotSupportMsg);
        return;
    }
    if (defaultAlgorithm.equals(validAlgorithmsKeyGenerator[validAlgorithmsKeyGenerator.length - 1])) {
        return;
    }
    int[] size = { Integer.MIN_VALUE, -1, 0, 112, 168, Integer.MAX_VALUE };
    KeyGenerator[] kgs = createKGs();
    SecureRandom random = new SecureRandom();
    for (int i = 0; i < kgs.length; i++) {
        for (int j = 0; j < size.length; j++) {
            try {
                kgs[i].init(size[j]);
                flag &= 0xE;
            } catch (InvalidParameterException ignore) {
                flag &= 0xD;
            }
            try {
                kgs[i].init(size[j], random);
                flag &= 0xB;
            } catch (InvalidParameterException ignore) {
                flag &= 0x7;
            }
        }
    }
    assertTrue(flag == 0);
}
Also used : InvalidParameterException(java.security.InvalidParameterException) SecureRandom(java.security.SecureRandom) KeyGenerator(javax.crypto.KeyGenerator)

Example 77 with SecureRandom

use of java.security.SecureRandom in project robovm by robovm.

the class CipherInputStream1Test method test_ConstructorLjava_io_InputStreamLjavax_crypto_Cipher.

public void test_ConstructorLjava_io_InputStreamLjavax_crypto_Cipher() throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
    ByteArrayInputStream bais = new ByteArrayInputStream(new byte[100]);
    KeyGenerator kg = KeyGenerator.getInstance("DES");
    kg.init(56, new SecureRandom());
    Key key = kg.generateKey();
    Cipher c = Cipher.getInstance("DES/CBC/NoPadding");
    c.init(Cipher.ENCRYPT_MODE, key);
    CipherInputStream cis = new CipherInputStream(bais, c);
    assertNotNull(cis);
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SecureRandom(java.security.SecureRandom) NullCipher(javax.crypto.NullCipher) Cipher(javax.crypto.Cipher) KeyGenerator(javax.crypto.KeyGenerator) Key(java.security.Key)

Example 78 with SecureRandom

use of java.security.SecureRandom in project UltimateRecyclerView by cymcsg.

the class SimpleAnimationAdapter method onBindHeaderViewHolder.

@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    TextView textView = (TextView) viewHolder.itemView.findViewById(R.id.stick_text);
    textView.setText(String.valueOf(getItem(position).charAt(0)));
    //        viewHolder.itemView.setBackgroundColor(Color.parseColor("#AA70DB93"));
    viewHolder.itemView.setBackgroundColor(Color.parseColor("#AAffffff"));
    ImageView imageView = (ImageView) viewHolder.itemView.findViewById(R.id.stick_img);
    SecureRandom imgGen = new SecureRandom();
    switch(imgGen.nextInt(3)) {
        case 0:
            imageView.setImageResource(R.drawable.scn1);
            break;
        case 1:
            imageView.setImageResource(R.drawable.jr13);
            break;
        case 2:
            imageView.setImageResource(R.drawable.jr16);
            break;
    }
}
Also used : SecureRandom(java.security.SecureRandom) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 79 with SecureRandom

use of java.security.SecureRandom in project UltimateRecyclerView by cymcsg.

the class sectionCommonAdapter method onBindHeaderViewHolder.

/**
     * this is the section header binding
     *
     * @param viewHolder section holder
     * @param position   position
     */
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
    TextView textView = (TextView) viewHolder.itemView.findViewById(R.id.stick_text);
    textView.setText(String.valueOf(getItem(hasHeaderView() ? position - 1 : position).charAt(0)));
    //        viewHolder.itemView.setBackgroundColor(Color.parseColor("#AA70DB93"));
    viewHolder.itemView.setBackgroundColor(Color.parseColor("#AAffffff"));
    ImageView imageView = (ImageView) viewHolder.itemView.findViewById(R.id.stick_img);
    SecureRandom imgGen = new SecureRandom();
    switch(imgGen.nextInt(3)) {
        case 0:
            imageView.setImageResource(R.drawable.scn1);
            break;
        case 1:
            imageView.setImageResource(R.drawable.jr13);
            break;
        case 2:
            imageView.setImageResource(R.drawable.jr16);
            break;
    }
}
Also used : SecureRandom(java.security.SecureRandom) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Example 80 with SecureRandom

use of java.security.SecureRandom in project UltimateRecyclerView by cymcsg.

the class sectionZeroAdapter method withBindHolder.

/*
    @Override
    public long generateHeaderId(int position) {
        // URLogs.d("position--" + position + "   " + getItem(position));
        if (getItem(position).length() > 0)
            return getItem(position).charAt(0);
        else return -1;
    }*/
@Override
protected void withBindHolder(itemCommonBinder holder, String data, int position) {
    holder.textViewSample.setText(data + "just the sample data");
    holder.item_view.setBackgroundColor(Color.parseColor("#AAffffff"));
    SecureRandom imgGen = new SecureRandom();
    switch(imgGen.nextInt(3)) {
        case 0:
            holder.imageViewSample.setImageResource(R.drawable.scn1);
            break;
        case 1:
            holder.imageViewSample.setImageResource(R.drawable.jr13);
            break;
        case 2:
            holder.imageViewSample.setImageResource(R.drawable.jr16);
            break;
    }
}
Also used : SecureRandom(java.security.SecureRandom)

Aggregations

SecureRandom (java.security.SecureRandom)720 SSLContext (javax.net.ssl.SSLContext)106 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)97 IOException (java.io.IOException)87 Test (org.junit.Test)76 SecretKey (javax.crypto.SecretKey)62 X509Certificate (java.security.cert.X509Certificate)61 KeyGenerator (javax.crypto.KeyGenerator)57 TrustManager (javax.net.ssl.TrustManager)56 X509TrustManager (javax.net.ssl.X509TrustManager)47 Cipher (javax.crypto.Cipher)46 KeyPairGenerator (java.security.KeyPairGenerator)44 BigInteger (java.math.BigInteger)42 CertificateException (java.security.cert.CertificateException)40 InvalidKeyException (java.security.InvalidKeyException)35 KeyPair (java.security.KeyPair)34 KeyStore (java.security.KeyStore)34 SecretKeySpec (javax.crypto.spec.SecretKeySpec)30 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)28 KeyManagementException (java.security.KeyManagementException)28