Examples of generateKey()


Examples of javax.crypto.KeyGenerator.generateKey()

        {
            KeyGenerator keyGen = KeyGenerator.getInstance(algorithm);

            keyGen.init(keySize);

            return keyGen.generateKey();
        }
        catch (NoSuchAlgorithmException e)
        {
            _log.error("Unsupported algorithm: " + algorithm + ", size: " + keySize, e);
            return null;
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

    public EncryptedKey(char[] password)
            throws Exception {

        KeyGenerator keyGen = KeyGenerator.getInstance(CRYPTO_ALGORITHM);
        keyGen.init(KEY_SIZE);
        SecretKey key = keyGen.generateKey();
        this.secretKey = key;
        this.encryptedKey = getEncrypted(secretKey.getEncoded(), password);
    }

    public EncryptedKey(byte[] encryptedKey, char[] password) {
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

   */
  public static byte[] createAESKey() {
    try {
          KeyGenerator kgen = KeyGenerator.getInstance("AES");
          kgen.init(0x100);
          SecretKey skey = kgen.generateKey();
          return skey.getEncoded();
        } catch (NoSuchAlgorithmException e) {
           throw new IllegalArgumentException("Cannot find key generator: AES", e);
        }
  }
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

      System.out.println("Decrypted: "+theMsg);

      // Try a key that should fail
      KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
      kgen.init(320);
      SecretKey key = kgen.generateKey();
      cipher.init(Cipher.DECRYPT_MODE, key);
      try
      {
         String tmp = (String) msg.getObject(cipher);
         throw new IllegalArgumentException("Should have failed to decrypt the msg");
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

   static void testKey() throws Exception
   {
      int size = 8 * 24;
      KeyGenerator kgen = KeyGenerator.getInstance("Blowfish");
      kgen.init(size);
      SecretKey key = kgen.generateKey();
      byte[] kbytes = key.getEncoded();
      System.out.println("key.Algorithm = "+key.getAlgorithm());
      System.out.println("key.Format = "+key.getFormat());
      System.out.println("key.Encoded Size = "+kbytes.length);
     
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

        try {
            KeyGenerator generator = provider == null
                                     ? KeyGenerator.getInstance(cipherName)
                                     : KeyGenerator.getInstance(cipherName,
                                         provider);
            SecretKey key = generator.generateKey();
            byte[]    raw = key.getEncoded();

            return raw;
        } catch (java.security.NoSuchAlgorithmException e) {
            throw Error.error(ErrorCode.X_S0531, e);
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

            byte[] seed = new byte[20];

            KeyGenerator key = KeyGenerator.getInstance("AES");           
            key.init(192, new SecureRandom());
            SecretKey sk = key.generateKey();           
            System.arraycopy(sk.getEncoded(), 0, seed, 0, 20); // create the 20 bytes seed
               
           
            Iterator it = policy.getRecipientsIterator();
            int i = 0;
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

        ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(algorithmparameters.getEncoded("ASN.1"));
        ASN1InputStream asn1inputstream = new ASN1InputStream(bytearrayinputstream);
        DERObject derobject = asn1inputstream.readObject();
        KeyGenerator keygenerator = KeyGenerator.getInstance(s);
        keygenerator.init(128);
        SecretKey secretkey = keygenerator.generateKey();
        Cipher cipher = Cipher.getInstance(s);
        cipher.init(1, secretkey, algorithmparameters);
        byte[] abyte1 = cipher.doFinal(in);
        DEROctetString deroctetstring = new DEROctetString(abyte1);
        KeyTransRecipientInfo keytransrecipientinfo = computeRecipientInfo(cert, secretkey.getEncoded());
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

  public SecretKey generateKey(final String iAlgorithm, final int iKeySize) {
    KeyGenerator kg;
    try {
      kg = KeyGenerator.getInstance(iAlgorithm);
      kg.init(iKeySize);
      return kg.generateKey();
    } catch (Exception e) {
      throw new OSecurityException("Error on generating key for algorithm: " + iAlgorithm, e);
    }
  }
View Full Code Here

Examples of javax.crypto.KeyGenerator.generateKey()

        Document document = builder.parse(sourceDocument);
       
        // Set up the Key
        KeyGenerator keygen = KeyGenerator.getInstance("AES");
        keygen.init(256);
        SecretKey secretKey = keygen.generateKey();
       
        // Encrypt using DOM
        List<String> localNames = new ArrayList<String>();
        localNames.add("PaymentInfo");
        encryptUsingDOM(
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.