Examples of doFinal()


Examples of javax.crypto.Cipher.doFinal()

    try {
          SecretKeySpec skeySpec = new SecretKeySpec(key, "AES");
          IvParameterSpec ivSpec = new IvParameterSpec(iv);
          Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
          cipher.init(Cipher.DECRYPT_MODE, skeySpec, ivSpec);
          return cipher.doFinal(encrypted);
    } catch(InvalidKeyException e) {
      throw new IllegalArgumentException(
          "if you see 'java.security.InvalidKeyException: Illegal key size', it cause by default JCE does not support 256-aes key for shipping reason.\n" +
          "but you can download those two policy files" +
          "    (US_export_policy.jar,local_policy.jar : Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files) " +
View Full Code Here

Examples of javax.crypto.Cipher.doFinal()

    protected byte[] encrypt(RSAPublicKey publicKey, byte[] obj) {
        if (publicKey != null) {
            try {
                Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
                cipher.init(Cipher.ENCRYPT_MODE, publicKey);
                return cipher.doFinal(obj);
            } catch (Exception e){
                e.printStackTrace();
            }
        }
        return null;
View Full Code Here

Examples of javax.crypto.Cipher.doFinal()

        if (privateKey != null) {
                try{
                    Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");

                    cipher.init(Cipher.DECRYPT_MODE, privateKey);
                    return cipher.doFinal(obj);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
   
View Full Code Here

Examples of javax.crypto.Cipher.doFinal()

      KeySpec keySpec = new DESKeySpec(passPhrase);
      SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(
          keySpec);
      Cipher cipher = Cipher.getInstance(key.getAlgorithm());
      cipher.init(Cipher.ENCRYPT_MODE, key);
      return toHexString(cipher.doFinal(msg.getBytes()));
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

Examples of javax.crypto.Cipher.doFinal()

      KeySpec keySpec = new DESKeySpec(passPhrase);
      SecretKey key = SecretKeyFactory.getInstance("DES").generateSecret(
          keySpec);
      Cipher cipher = Cipher.getInstance(key.getAlgorithm());
      cipher.init(Cipher.DECRYPT_MODE, key);
      return new String(cipher.doFinal(fromHexString(msg)));
    } catch (Exception e) {
      return null;
    }
  }
View Full Code Here

Examples of javax.crypto.Cipher.doFinal()

         sm.checkPermission(encodePermission);
      }

      Cipher cipher = Cipher.getInstance(cipherAlgorithm);
      cipher.init(Cipher.ENCRYPT_MODE, cipherKey, cipherSpec);
      byte[] encoding = cipher.doFinal(secret);
      return encoding;
   }

   /*
    * (non-Javadoc)
 
View Full Code Here

Examples of javax.crypto.Cipher.doFinal()

      if (sm != null)
         sm.checkPermission(decodePermission);

      Cipher cipher = Cipher.getInstance(cipherAlgorithm);
      cipher.init(Cipher.DECRYPT_MODE, cipherKey, cipherSpec);
      byte[] decode = cipher.doFinal(secret);
      return decode;
   }

   /*
    * (non-Javadoc)
 
View Full Code Here

Examples of javax.crypto.Mac.doFinal()

                // also should not happen
                throw new RuntimeException("Could not initialize the MAC algorithm", e);
            }

            // Compute the HMAC on the digest, and set it.
            String b64=Base64.encodeBytes(mac.doFinal(canonicalString.getBytes()));

            if(urlencode) {
                return urlencode(b64);
            }
            else {
View Full Code Here

Examples of javax.crypto.Mac.doFinal()

          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
   
          return encodeBase64(rawHmac);
         
      } catch (NoSuchAlgorithmException nsae) {
          throw new IOException("required algorithm HmacSHA1 is not supported by environment: " + nsae.toString());
View Full Code Here

Examples of javax.crypto.Mac.doFinal()

            String algorithm = _macKey.getAlgorithm();
            Mac mac = Mac.getInstance(algorithm);

            mac.init(_macKey);

            return mac.doFinal(data);
        }
        catch (GeneralSecurityException e)
        {
            throw new AssociationException("Cannot sign!", e);
        }
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.