Java Code Examples for javax.crypto.Cipher

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project android-bankdroid, under directory /src/net/sf/andhsli/hotspotlogin/.

Source file: SimpleCrypto.java

  41 
vote

private static byte[] encrypt(byte[] raw,byte[] clear) throws Exception {
  SecretKeySpec skeySpec=new SecretKeySpec(raw,"AES");
  Cipher cipher=Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
  byte[] encrypted=cipher.doFinal(clear);
  return encrypted;
}
 

Example 2

From project aws-tvm-anonymous, under directory /src/com/amazonaws/tvm/.

Source file: AESEncryption.java

  38 
vote

public static byte[] encrypt(String clearText,String key,byte[] iv) throws Exception {
  Cipher cipher=Cipher.getInstance(ENCRYPTION_ALGORITHM);
  AlgorithmParameters params=AlgorithmParameters.getInstance("AES");
  params.init(new IvParameterSpec(iv));
  cipher.init(Cipher.ENCRYPT_MODE,getKey(key),params);
  return cipher.doFinal(clearText.getBytes());
}
 

Example 3

From project cogroo4, under directory /lang/pt_br/cogroo-addon/src/org/cogroo/addon/util/.

Source file: SecurityUtil.java

  35 
vote

/** 
 * Encrypt data using an key encrypted with a private key.
 * @param privateKey the private key to decrypt the secret key
 * @param encryptedSecretKey a encrypted secret key
 * @param data the data to encrypt
 * @return the encrypted data
 * @throws InvalidKeyException one of the keys is invalid
 */
public byte[] encrypt(PrivateKey privateKey,byte[] encryptedSecretKey,String data) throws InvalidKeyException {
  byte[] encryptedData=null;
  try {
    byte[] chave=privateKey.getEncoded();
    Cipher rsacf=Cipher.getInstance("RSA");
    rsacf.init(Cipher.DECRYPT_MODE,privateKey);
    byte[] secretKey=rsacf.doFinal(encryptedSecretKey);
    encryptedData=encrypt(secretKey,data);
  }
 catch (  Exception e) {
    LOG.log(Level.SEVERE,"Exception encrypting data",e);
  }
  return encryptedData;
}
 

Example 4

From project connectbot, under directory /src/sk/vx/connectbot/util/.

Source file: PubkeyUtils.java

  35 
vote

public static byte[] cipher(int mode,byte[] data,byte[] secret) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
  SecretKeySpec secretKeySpec=new SecretKeySpec(sha256(secret),"AES");
  Cipher c=Cipher.getInstance("AES");
  c.init(mode,secretKeySpec);
  return c.doFinal(data);
}
 

Example 5

From project aws-tvm-identity, under directory /src/com/amazonaws/tvm/.

Source file: AESEncryption.java

  33 
vote

public static byte[] encrypt(String clearText,String key,byte[] iv) throws Exception {
  Cipher cipher=Cipher.getInstance(ENCRYPTION_ALGORITHM);
  AlgorithmParameters params=AlgorithmParameters.getInstance("AES");
  params.init(new IvParameterSpec(iv));
  cipher.init(Cipher.ENCRYPT_MODE,getKey(key),params);
  return cipher.doFinal(clearText.getBytes());
}
 

Example 6

From project BF3-Battlelog, under directory /src/net/sf/andhsli/hotspotlogin/.

Source file: SimpleCrypto.java

  33 
vote

private static byte[] encrypt(byte[] raw,byte[] clear) throws Exception {
  SecretKeySpec skeySpec=new SecretKeySpec(raw,"AES");
  Cipher cipher=Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
  byte[] encrypted=cipher.doFinal(clear);
  return encrypted;
}
 

Example 7

From project clutter, under directory /src/clutter/hypertoolkit/security/.

Source file: ClearText.java

  33 
vote

public CipherText encrypt(SecretKey secretKey){
  try {
    Cipher cipher=Cipher.getInstance("AES");
    cipher.init(Cipher.ENCRYPT_MODE,secretKey);
    byte[] encrypted=cipher.doFinal(bytes);
    return new CipherText(encrypted);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 8

From project Cours-3eme-ann-e, under directory /Java/FerryInpres/src/identity_server/.

Source file: IdentityApplic.java

  33 
vote

public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException, NoSuchAlgorithmException, NoSuchPaddingException, IllegalBlockSizeException, BadPaddingException, InvalidKeyException {
  prop=new Properties();
  prop.load(new FileInputStream("ferryinpres.properties"));
  Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
  Socket sock=new Socket(prop.getProperty("IDENTITY_SERVER"),Integer.parseInt(prop.getProperty("IDENTITY_PORT")));
  ObjectOutputStream out=new ObjectOutputStream(sock.getOutputStream());
  ObjectInputStream in=new ObjectInputStream(sock.getInputStream());
  SecretKey sessionKey=keyExchange(in,out);
  Cipher cryptor=Cipher.getInstance("DES/ECB/PKCS5Padding");
  cryptor.init(Cipher.ENCRYPT_MODE,sessionKey);
  Cipher decryptor=Cipher.getInstance("DES/ECB/PKCS5Padding");
  decryptor.init(Cipher.DECRYPT_MODE,sessionKey);
  login(in,out,cryptor,decryptor);
}
 

Example 9

From project droidparts, under directory /extra/src/org/droidparts/util/crypto/.

Source file: Crypter.java

  33 
vote

private static byte[] encrypt(byte[] raw,byte[] clear) throws Exception {
  SecretKeySpec skeySpec=new SecretKeySpec(raw,"AES");
  Cipher cipher=Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
  byte[] encrypted=cipher.doFinal(clear);
  return encrypted;
}
 

Example 10

From project Eclipse, under directory /com.mobilesorcery.sdk.core/src/com/mobilesorcery/sdk/internal/.

Source file: SecureProperties.java

  33 
vote

private Cipher createCipher(int mode,byte[] salt) throws GeneralSecurityException {
  SecretKeyFactory keyFactory;
  keyFactory=SecretKeyFactory.getInstance(KEY_FACTORY);
  SecretKey key=keyFactory.generateSecret(password);
  PBEParameterSpec entropy=new PBEParameterSpec(salt,8);
  Cipher cipher=Cipher.getInstance(CIPHER);
  cipher.init(mode,key,entropy);
  return cipher;
}
 

Example 11

From project encfs-java, under directory /src/main/java/org/mrpdaemon/sec/encfs/.

Source file: EncFSCrypto.java

  33 
vote

/** 
 * Returns a new stream cipher with AES/CFB/NoPadding.
 * @return A new Cipher object.
 * @throws EncFSUnsupportedException AES/CFB/NoPadding not supported by this runtime
 */
public static Cipher newStreamCipher() throws EncFSUnsupportedException {
  Cipher result=null;
  try {
    result=Cipher.getInstance("AES/CFB/NoPadding");
  }
 catch (  NoSuchAlgorithmException e) {
    throw new EncFSUnsupportedException(e);
  }
catch (  NoSuchPaddingException e) {
    throw new EncFSUnsupportedException(e);
  }
  return result;
}
 

Example 12

From project entando-core-engine, under directory /src/main/java/com/agiletec/aps/util/.

Source file: DefaultApsEncrypter.java

  33 
vote

public static String decrypt(String source){
  try {
    Key key=getKey();
    Cipher desCipher=Cipher.getInstance(TRIPLE_DES);
    byte[] dec=Base64.decodeBase64(source.getBytes());
    desCipher.init(Cipher.DECRYPT_MODE,key);
    byte[] cleartext=desCipher.doFinal(dec);
    return new String(cleartext);
  }
 catch (  Throwable t) {
    throw new RuntimeException("Error decrypting string",t);
  }
}
 

Example 13

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/codec/crypto/.

Source file: CipherCodec.java

  33 
vote

/** 
 * {@inheritDoc}
 * @see net.sf.hajdbc.codec.Codec#decode(java.lang.String)
 */
@Override public String decode(String value) throws SQLException {
  try {
    Cipher cipher=Cipher.getInstance(this.key.getAlgorithm());
    cipher.init(Cipher.DECRYPT_MODE,this.key);
    return new String(cipher.doFinal(Base64.decodeBase64(value.getBytes())));
  }
 catch (  GeneralSecurityException e) {
    throw new SQLException(e);
  }
}
 

Example 14

From project http-testing-harness, under directory /server-provider/src/main/java/org/sonatype/tests/http/server/jetty/behaviour/.

Source file: NTLMAuth.java

  33 
vote

private Cipher getCipher(byte[] key) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException {
  final Cipher ecipher=Cipher.getInstance("DES/ECB/NoPadding");
  key=setupKey(key);
  ecipher.init(Cipher.ENCRYPT_MODE,new SecretKeySpec(key,"DES"));
  return ecipher;
}
 

Example 15

From project JAirPort, under directory /src/de/debugco/jairport/.

Source file: Utils.java

  33 
vote

public static byte[] decrypt(byte[] data){
  try {
    Cipher c=getRsaCipher("OAEPWITHSHA1ANDMGF1PADDING");
    c.init(Cipher.DECRYPT_MODE,getKey());
    return c.doFinal(data);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 16

From project james-mime4j, under directory /storage/src/main/java/org/apache/james/mime4j/storage/.

Source file: CipherStorageProvider.java

  33 
vote

public CipherStorageOutputStream(StorageOutputStream out,String algorithm,SecretKeySpec skeySpec) throws IOException {
  try {
    this.storageOut=out;
    this.algorithm=algorithm;
    this.skeySpec=skeySpec;
    Cipher cipher=Cipher.getInstance(algorithm);
    cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
    this.cipherOut=new CipherOutputStream(out,cipher);
  }
 catch (  GeneralSecurityException e) {
    throw (IOException)new IOException().initCause(e);
  }
}
 

Example 17

From project jAPS2, under directory /src/com/agiletec/aps/util/.

Source file: DefaultApsEncrypter.java

  33 
vote

public static String decrypt(String source){
  try {
    Key key=getKey();
    Cipher desCipher=Cipher.getInstance(TRIPLE_DES);
    byte[] dec=Base64.decodeBase64(source.getBytes());
    desCipher.init(Cipher.DECRYPT_MODE,key);
    byte[] cleartext=desCipher.doFinal(dec);
    return new String(cleartext);
  }
 catch (  Throwable t) {
    throw new RuntimeException("Error decrypting string",t);
  }
}
 

Example 18

From project jBilling, under directory /src/java/com/sapienter/jbilling/common/.

Source file: JBCryptoImpl.java

  33 
vote

public String decrypt(String cryptedText){
  Cipher cipher=getCipher();
  byte[] crypted=useHexForBinary ? Util.stringToBinary(cryptedText) : Base64.decodeBase64(cryptedText.getBytes());
  byte[] result;
  try {
    cipher.init(Cipher.DECRYPT_MODE,mySecretKey,ourPBEParameters);
    result=cipher.doFinal(crypted);
  }
 catch (  GeneralSecurityException e) {
    throw new IllegalArgumentException("Can not decrypt:" + cryptedText,e);
  }
  return new String(result,UTF8);
}
 

Example 19

From project maven-wagon, under directory /wagon-providers/wagon-ssh-common-test/src/main/java/org/apache/maven/wagon/providers/ssh/.

Source file: TestPublickeyAuthenticator.java

  33 
vote

public static byte[] decrypt(byte[] text,PrivateKey key) throws Exception {
  byte[] dectyptedText=null;
  Cipher cipher=Cipher.getInstance("RSA/ECB/PKCS1Padding");
  cipher.init(Cipher.DECRYPT_MODE,key);
  dectyptedText=cipher.doFinal(text);
  return dectyptedText;
}
 

Example 20

From project Monetizing-Android-Demo-Project, under directory /src/dk/trifork/geeknight/bigredbutton/.

Source file: SimpleCrypto.java

  33 
vote

private static byte[] encrypt(byte[] raw,byte[] clear) throws Exception {
  SecretKeySpec skeySpec=new SecretKeySpec(raw,"AES");
  Cipher cipher=Cipher.getInstance("AES");
  cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
  byte[] encrypted=cipher.doFinal(clear);
  return encrypted;
}
 

Example 21

From project Newsreader, under directory /bundles/org.apache.mime4j/src/org/apache/james/mime4j/storage/.

Source file: CipherStorageProvider.java

  33 
vote

public CipherStorageOutputStream(StorageOutputStream out,String algorithm,SecretKeySpec skeySpec) throws IOException {
  try {
    this.storageOut=out;
    this.algorithm=algorithm;
    this.skeySpec=skeySpec;
    Cipher cipher=Cipher.getInstance(algorithm);
    cipher.init(Cipher.ENCRYPT_MODE,skeySpec);
    this.cipherOut=new CipherOutputStream(out,cipher);
  }
 catch (  GeneralSecurityException e) {
    throw (IOException)new IOException().initCause(e);
  }
}
 

Example 22

From project JGlobus, under directory /ssl-proxies/src/main/java/org/globus/gsi/.

Source file: OpenSSLKey.java

  32 
vote

/** 
 * Decrypts the private key with given password. Does nothing if the key is not encrypted.
 * @param password password to decrypt the key with.
 * @throws GeneralSecurityException whenever an error occurs during decryption.
 */
public void decrypt(byte[] password) throws GeneralSecurityException {
  if (!isEncrypted()) {
    return;
  }
  byte[] enc=Base64.decode(this.encodedKey);
  SecretKeySpec key=getSecretKey(password,this.initializationVector.getIV());
  Cipher cipher=getCipher();
  cipher.init(Cipher.DECRYPT_MODE,key,this.initializationVector);
  enc=cipher.doFinal(enc);
  this.intKey=getKey(this.keyAlg,enc);
  this.keyData=enc;
  this.isEncrypted=false;
  this.encodedKey=null;
}
 

Example 23

From project keepassdroid, under directory /src/com/keepassdroid/crypto/.

Source file: CipherFactory.java

  32 
vote

/** 
 * Generate appropriate cipher based on KeePass 2.x UUID's
 * @param uuid
 * @return
 * @throws NoSuchPaddingException 
 * @throws NoSuchAlgorithmException 
 * @throws InvalidAlgorithmParameterException 
 * @throws InvalidKeyException 
 */
public static Cipher getInstance(UUID uuid,byte[] key,byte[] IV) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException {
  if (uuid.equals(AES_CIPHER)) {
    Cipher cipher=CipherFactory.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.DECRYPT_MODE,new SecretKeySpec(key,"AES"),new IvParameterSpec(IV));
    return cipher;
  }
  throw new NoSuchAlgorithmException("UUID unrecognized.");
}
 

Example 24

From project lor-jamwiki, under directory /jamwiki-core/src/main/java/org/jamwiki/utils/.

Source file: Encryption.java

  32 
vote

/** 
 * Encrypt a String value using the DES encryption algorithm.
 * @param unencryptedBytes The unencrypted String value that is to be encrypted.
 * @return An encrypted version of the String that was passed to this method.
 */
private static String encrypt64(byte[] unencryptedBytes) throws GeneralSecurityException, UnsupportedEncodingException {
  if (unencryptedBytes == null || unencryptedBytes.length == 0) {
    throw new IllegalArgumentException("Cannot encrypt a null or empty byte array");
  }
  SecretKey key=createKey();
  Cipher cipher=Cipher.getInstance(key.getAlgorithm());
  cipher.init(Cipher.ENCRYPT_MODE,key);
  byte[] encryptedBytes=Base64.encodeBase64(cipher.doFinal(unencryptedBytes));
  return bytes2String(encryptedBytes);
}
 

Example 25

From project narya, under directory /core/src/main/java/com/threerings/presents/util/.

Source file: SecureUtil.java

  32 
vote

/** 
 * Creates our AES cipher.
 */
public static Cipher getAESCipher(int mode,byte[] key){
  try {
    Cipher cipher=Cipher.getInstance("AES/CBC/PKCS5Padding");
    SecretKeySpec aesKey=new SecretKeySpec(key,"AES");
    cipher.init(mode,aesKey,IVPS);
    return cipher;
  }
 catch (  GeneralSecurityException gse) {
    log.warning("Failed to create cipher",gse);
  }
  return null;
}
 

Example 26

From project OAK, under directory /oak-library/src/main/java/oak/.

Source file: ObscuredSharedPreferences.java

  32 
vote

protected String encrypt(String value){
  try {
    final byte[] bytes=value != null ? value.getBytes(UTF8) : new byte[0];
    SecretKeyFactory keyFactory=SecretKeyFactory.getInstance("PBEWithMD5AndDES");
    SecretKey key=keyFactory.generateSecret(new PBEKeySpec(getSpecialCode()));
    Cipher pbeCipher=Cipher.getInstance("PBEWithMD5AndDES");
    pbeCipher.init(Cipher.ENCRYPT_MODE,key,new PBEParameterSpec(getAndroidId().getBytes(UTF8),20));
    return new String(Base64.encode(pbeCipher.doFinal(bytes),Base64.NO_WRAP),UTF8);
  }
 catch (  Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 27

From project ODE-X, under directory /runtime/src/main/java/org/apache/ode/runtime/exec/platform/.

Source file: NodeImpl.java

  32 
vote

public static String encrypt(String b64EncKey,String cleartext) throws Exception {
  byte[] encKey=DatatypeConverter.parseBase64Binary(b64EncKey);
  SecretKeySpec key=new SecretKeySpec(encKey,"AES");
  Cipher cipher=Cipher.getInstance("AES/ECB/PKCS5Padding");
  cipher.init(Cipher.ENCRYPT_MODE,key);
  return DatatypeConverter.printBase64Binary(cipher.doFinal(cleartext.getBytes("UTF-8")));
}
 

Example 28

From project Ohmage_Phone, under directory /src/edu/ucla/cens/pdc/libpdc/util/.

Source file: EncryptionHelper.java

  32 
vote

public static byte[] wrapKey(PublicKey public_key,SecretKey secret_key) throws PDCEncryptionException {
  String alg;
  Cipher cipher;
  alg=public_key.getAlgorithm() + "/ECB/PKCS1Padding";
  try {
    cipher=Cipher.getInstance(alg);
    cipher.init(Cipher.WRAP_MODE,public_key);
    return cipher.wrap(secret_key);
  }
 catch (  GeneralSecurityException ex) {
    throw new PDCEncryptionException("Unable to wrap key in " + public_key.toString(),ex);
  }
}
 

Example 29

From project Ohmage_Server_2, under directory /src/edu/ucla/cens/pdc/libpdc/util/.

Source file: EncryptionHelper.java

  32 
vote

public static byte[] wrapKey(PublicKey public_key,SecretKey secret_key) throws PDCEncryptionException {
  String alg;
  Cipher cipher;
  alg=public_key.getAlgorithm() + "/ECB/PKCS1Padding";
  try {
    cipher=Cipher.getInstance(alg);
    cipher.init(Cipher.WRAP_MODE,public_key);
    return cipher.wrap(secret_key);
  }
 catch (  GeneralSecurityException ex) {
    throw new PDCEncryptionException("Unable to wrap key in " + public_key.toString(),ex);
  }
}
 

Example 30

From project OpenID-Connect-Java-Spring-Server, under directory /openid-connect-common/src/main/java/org/mitre/jwt/encryption/impl/.

Source file: RsaDecrypter.java

  32 
vote

@Override public byte[] decryptEncryptionKey(Jwe jwe) throws NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeyException, IllegalBlockSizeException, BadPaddingException {
  if (jwe.getHeader().getAlgorithm().equals("RSA1_5")) {
    Cipher cipher=Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE,getPrivateKey());
    byte[] contentMasterKey=cipher.doFinal(jwe.getEncryptedKey());
    return contentMasterKey;
  }
 else {
    throw new IllegalArgumentException(jwe.getHeader().getAlgorithm() + " is not an implemented algorithm");
  }
}
 

Example 31

From project ajah, under directory /ajah-crypto/src/main/java/com/ajah/crypto/.

Source file: Crypto.java

  31 
vote

/** 
 * Accepts a hexadecimal encoded version of the encrypted data and decrypts it.
 * @param encrypted hexadecimal encoded version of the encrypted data
 * @param keyString The key to use to decrypt the data.
 * @return Decrypted version.
 * @throws UnsupportedOperationException If there is a cryptographic error.
 */
public static String fromAES(final String encrypted,String keyString){
  final SecretKeySpec skeySpec=new SecretKeySpec(new BigInteger(keyString,16).toByteArray(),"AES");
  try {
    final Cipher cipher=Cipher.getInstance("AES");
    cipher.init(Cipher.DECRYPT_MODE,skeySpec);
    return new String(cipher.doFinal(new BigInteger(encrypted,16).toByteArray()));
  }
 catch (  final InvalidKeyException e) {
    throw new UnsupportedOperationException(e);
  }
catch (  final IllegalBlockSizeException e) {
    throw new UnsupportedOperationException(e);
  }
catch (  final BadPaddingException e) {
    throw new UnsupportedOperationException(e);
  }
catch (  final NoSuchAlgorithmException e) {
    throw new UnsupportedOperationException(e);
  }
catch (  final NoSuchPaddingException e) {
    throw new UnsupportedOperationException(e);
  }
}
 

Example 32

From project AmDroid, under directory /httpclientandroidlib/src/ch/boye/httpclientandroidlib/impl/auth/.

Source file: NTLMEngineImpl.java

  31 
vote

/** 
 * Creates the LM Hash of the user's password.
 * @param password The password.
 * @return The LM Hash of the given password, used in the calculation of theLM Response.
 */
private static byte[] lmHash(String password) throws NTLMEngineException {
  try {
    byte[] oemPassword=password.toUpperCase().getBytes("US-ASCII");
    int length=Math.min(oemPassword.length,14);
    byte[] keyBytes=new byte[14];
    System.arraycopy(oemPassword,0,keyBytes,0,length);
    Key lowKey=createDESKey(keyBytes,0);
    Key highKey=createDESKey(keyBytes,7);
    byte[] magicConstant="KGS!@#$%".getBytes("US-ASCII");
    Cipher des=Cipher.getInstance("DES/ECB/NoPadding");
    des.init(Cipher.ENCRYPT_MODE,lowKey);
    byte[] lowHash=des.doFinal(magicConstant);
    des.init(Cipher.ENCRYPT_MODE,highKey);
    byte[] highHash=des.doFinal(magicConstant);
    byte[] lmHash=new byte[16];
    System.arraycopy(lowHash,0,lmHash,0,8);
    System.arraycopy(highHash,0,lmHash,8,8);
    return lmHash;
  }
 catch (  Exception e) {
    throw new NTLMEngineException(e.getMessage(),e);
  }
}
 

Example 33

From project Android_1, under directory /encryption/src/com/novoda/.

Source file: Encrypt.java

  31 
vote

public String crypt(int mode,String encryption_subject) throws Base64DecoderException, NoSuchAlgorithmException, InvalidAlgorithmParameterException, InvalidAlgorithmParameterException, InvalidKeyException, InvalidKeySpecException, NoSuchPaddingException, BadPaddingException, UnsupportedEncodingException, IllegalBlockSizeException {
  final PBEParameterSpec ps=new javax.crypto.spec.PBEParameterSpec(SALT,20);
  final SecretKeyFactory kf=SecretKeyFactory.getInstance(ALGORITHM);
  final SecretKey k=kf.generateSecret(new javax.crypto.spec.PBEKeySpec(SECRET_KEY.toCharArray()));
  final Cipher crypter=Cipher.getInstance(CIPHER_TYPE);
  String result;
switch (mode) {
case Cipher.DECRYPT_MODE:
    crypter.init(Cipher.DECRYPT_MODE,k,ps);
  result=new String(crypter.doFinal(Base64.decode(encryption_subject)),CHARSET);
break;
case Cipher.ENCRYPT_MODE:
default :
crypter.init(Cipher.ENCRYPT_MODE,k,ps);
result=Base64.encode(crypter.doFinal(encryption_subject.getBytes(CHARSET)));
}
return result;
}
 

Example 34

From project android_build, under directory /tools/signapk/.

Source file: SignApk.java

  31 
vote

/** 
 * Decrypt an encrypted PKCS 8 format private key. Based on ghstark's post on Aug 6, 2006 at http://forums.sun.com/thread.jspa?threadID=758133&messageID=4330949
 * @param encryptedPrivateKey The raw data of the private key
 * @param keyFile The file containing the private key
 */
private static KeySpec decryptPrivateKey(byte[] encryptedPrivateKey,File keyFile) throws GeneralSecurityException {
  EncryptedPrivateKeyInfo epkInfo;
  try {
    epkInfo=new EncryptedPrivateKeyInfo(encryptedPrivateKey);
  }
 catch (  IOException ex) {
    return null;
  }
  char[] password=readPassword(keyFile).toCharArray();
  SecretKeyFactory skFactory=SecretKeyFactory.getInstance(epkInfo.getAlgName());
  Key key=skFactory.generateSecret(new PBEKeySpec(password));
  Cipher cipher=Cipher.getInstance(epkInfo.getAlgName());
  cipher.init(Cipher.DECRYPT_MODE,key,epkInfo.getAlgParameters());
  try {
    return epkInfo.getKeySpec(cipher);
  }
 catch (  InvalidKeySpecException ex) {
    System.err.println("signapk: Password for " + keyFile + " may be bad.");
    throw ex;
  }
}
 

Example 35

From project candlepin, under directory /src/main/java/org/candlepin/config/.

Source file: EncryptedValueConfigurationParser.java

  31 
vote

public String decryptValue(String toDecrypt,String passphrase){
  log.info("decrypt called");
  if (!toDecrypt.startsWith("$1$")) {
    log.debug("this is not an encrypted string");
    return toDecrypt;
  }
  toDecrypt=toDecrypt.substring(3);
  try {
    Cipher cipher;
    cipher=Cipher.getInstance("AES/CBC/PKCS5Padding");
    String ivString=passphrase + passphrase;
    String iv=DigestUtils.sha256Hex(ivString);
    String passphraseDigest=DigestUtils.sha256Hex(passphrase);
    SecretKeySpec spec=new SecretKeySpec(Arrays.copyOfRange(passphraseDigest.getBytes(),0,32),"AES");
    cipher.init(Cipher.DECRYPT_MODE,spec,new IvParameterSpec(iv.getBytes(),0,16));
    log.info("gh10");
    byte[] b64bytes=Base64.decodeBase64(toDecrypt);
    String plaintext=new String(cipher.doFinal(b64bytes));
    return plaintext;
  }
 catch (  Exception e) {
    log.info("Failure trying to decrypt" + toDecrypt,e);
    throw new RuntimeException(e);
  }
}
 

Example 36

From project cas, under directory /cas-server-extension-clearpass/src/main/java/org/jasig/cas/extension/clearpass/.

Source file: EncryptedMapDecorator.java

  31 
vote

protected String decrypt(final String value,String hashedKey){
  if (value == null)   return null;
  try {
    final Cipher cipher=getCipherObject();
    byte[] ivByteArray=algorithmParametersHashMap.get(hashedKey).getIV();
    IvParameterSpec ivSpec=new IvParameterSpec(ivByteArray);
    cipher.init(Cipher.DECRYPT_MODE,this.key,ivSpec);
    byte[] valueByteArray=value.getBytes();
    byte[] decrypted64ByteValue=new Base64().decode(valueByteArray);
    byte[] decryptedByteArray=cipher.doFinal(decrypted64ByteValue);
    return new String(decryptedByteArray);
  }
 catch (  final Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 37

From project caseconductor-platform, under directory /utest-common/src/main/java/com/utest/util/.

Source file: CrytographicTool.java

  31 
vote

/** 
 * Encrypts a text.
 * @param source the plain text to encrypt.
 * @return the encrypted text.
 * @throws Exception
 */
public static String encrypt(final String source,final CryptoAlgorithm algorithm,final String blowfishKey) throws Exception {
  String result="";
  if (CryptoAlgorithm.BLOWFISH.equals(algorithm)) {
    final byte[] keyBytes=new BigInteger(blowfishKey,16).toByteArray();
    final Key key=new SecretKeySpec(keyBytes,"Blowfish");
    final BASE64Encoder encoder=new BASE64Encoder();
    final Cipher cipher=Cipher.getInstance("Blowfish/ECB/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE,key);
    final byte[] ciphertext=cipher.doFinal(source.getBytes("UTF8"));
    result=encoder.encode(ciphertext);
    return result;
  }
  if (CryptoAlgorithm.DES.equals(algorithm)) {
    result=DES.encrypt(source);
  }
  return result;
}
 

Example 38

From project chililog-server, under directory /src/main/java/org/chililog/server/common/.

Source file: CryptoUtils.java

  31 
vote

/** 
 * <p> Encrypt a plain text string using AES. The output is an encrypted plain text string. See http://stackoverflow.com/questions/992019/java-256bit-aes-encryption/992413#992413 </p> <p> The algorithm used is <code>base64(aes(plainText))</code> </p>
 * @param plainText text to encrypt
 * @param password password to use for encryption
 * @return encrypted text
 * @throws ChiliLogException
 */
public static String encryptAES(String plainText,String password) throws ChiliLogException {
  try {
    SecretKeyFactory factory=SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1");
    KeySpec spec=new PBEKeySpec(password.toCharArray(),AES_ENCRYPTION_STRING_SALT,1024,128);
    SecretKey tmp=factory.generateSecret(spec);
    SecretKey secret=new SecretKeySpec(tmp.getEncoded(),"AES");
    byte[] plainTextBytes=plainText.getBytes("UTF-8");
    AlgorithmParameterSpec paramSpec=new IvParameterSpec(AES_ENCRYPTION_INTIALIZATION_VECTOR);
    Cipher cipher=Cipher.getInstance("AES/CBC/PKCS5Padding");
    cipher.init(Cipher.ENCRYPT_MODE,secret,paramSpec);
    byte[] cipherText=cipher.doFinal(plainTextBytes);
    Base64 encoder=new Base64(1000,new byte[]{},false);
    return encoder.encodeToString(cipherText);
  }
 catch (  Exception ex) {
    throw new ChiliLogException(ex,"Error attempting to encrypt. " + ex.getMessage());
  }
}
 

Example 39

From project dnieprov, under directory /src/org/dnieprov/driver/.

Source file: DnieSecureChannel.java

  31 
vote

private byte[] cipher(byte data[],boolean encrypt) throws NoSuchAlgorithmException, BadPaddingException, IllegalBlockSizeException, InvalidAlgorithmParameterException, InvalidKeyException, NoSuchPaddingException {
  int dir=encrypt ? Cipher.ENCRYPT_MODE : Cipher.DECRYPT_MODE;
  byte[] keyTdesBytes=new byte[24];
  System.arraycopy(kenc,0,keyTdesBytes,0,16);
  System.arraycopy(kenc,0,keyTdesBytes,16,8);
  byte[] ivBytes=new byte[8];
  for (int i=0; i < 8; i++) {
    ivBytes[i]=0x00;
  }
  SecretKey keyTdes=new SecretKeySpec(keyTdesBytes,"DESede");
  Cipher des=Cipher.getInstance("DESede/CBC/NoPadding");
  IvParameterSpec iv=new IvParameterSpec(ivBytes);
  des.init(dir,keyTdes,iv);
  return des.doFinal(data);
}
 

Example 40

From project DTE, under directory /src/cl/nic/dte/util/.

Source file: Utilities.java

  31 
vote

public static PrivateKey readPrivateKey(byte[] datos,String algo,char[] password) throws IOException, NoSuchAlgorithmException, NoSuchPaddingException, InvalidKeySpecException, InvalidKeyException, InvalidAlgorithmParameterException {
  PKCS8EncodedKeySpec pkcs8KeySpec=null;
  if (password != null) {
    EncryptedPrivateKeyInfo ekey=new EncryptedPrivateKeyInfo(datos);
    Cipher cip=Cipher.getInstance(ekey.getAlgName());
    PBEKeySpec pspec=new PBEKeySpec(password);
    SecretKeyFactory skfac=SecretKeyFactory.getInstance(ekey.getAlgName());
    Key pbeKey=skfac.generateSecret(pspec);
    AlgorithmParameters algParams=ekey.getAlgParameters();
    cip.init(Cipher.DECRYPT_MODE,pbeKey,algParams);
    pkcs8KeySpec=ekey.getKeySpec(cip);
  }
 else {
    pkcs8KeySpec=new PKCS8EncodedKeySpec(datos);
  }
  KeyFactory rsaKeyFac=KeyFactory.getInstance(algo);
  return (PrivateKey)rsaKeyFac.generatePrivate(pkcs8KeySpec);
}
 

Example 41

From project dungbeetle, under directory /src/edu/stanford/mobisocial/dungbeetle/location/.

Source file: ClientClass.java

  31 
vote

public boolean sendSharedKey(long myID,byte[] sharedKey){
  try {
    RSAPublicKeySpec keySpec=new RSAPublicKeySpec(RSAmod,serverPK);
    KeyFactory fact=KeyFactory.getInstance("RSA");
    PublicKey pk=fact.generatePublic(keySpec);
    Cipher cipher=Cipher.getInstance("RSA/NONE/PKCS1Padding");
    cipher.init(Cipher.ENCRYPT_MODE,pk);
    byte[] encryptedData=cipher.doFinal(sharedKey);
    byte[] packet=new byte[9 + encryptedData.length];
    packet[0]=new Byte("7").byteValue();
    int startIndex=1;
    BigInteger convertToByte=BigInteger.valueOf(myID);
    byte[] byteRep=convertToByte.toByteArray();
    if (byteRep.length < 8) {
      for (int i=0; i < (8 - byteRep.length); i++) {
        packet[startIndex]=new Byte("0").byteValue();
        startIndex++;
      }
    }
    for (int i=0; i < byteRep.length; i++) {
      packet[startIndex]=byteRep[i];
      startIndex++;
    }
    for (int i=0; i < encryptedData.length; i++) {
      packet[startIndex]=encryptedData[i];
      startIndex++;
    }
    boolean result=sendPacketToServer(packet);
    return result;
  }
 catch (  Exception e) {
    return false;
  }
}
 

Example 42

From project en4j, under directory /NBPlatformApp/Synchronization/src/main/java/com/rubenlaguna/en4j/sync/.

Source file: EvernoteProtocolUtil.java

  31 
vote

private EvernoteProtocolUtil(){
  try {
    KeySpec keySpec=new PBEKeySpec("55xdfsfAxkioou546bnTrjk".toCharArray(),salt,iterationCount);
    SecretKey key=SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
    Cipher dcipher=Cipher.getInstance(key.getAlgorithm());
    AlgorithmParameterSpec paramSpec=new PBEParameterSpec(salt,iterationCount);
    dcipher.init(Cipher.DECRYPT_MODE,key,paramSpec);
    byte[] dec=new Base64().decode(consumerKey);
    byte[] utf8=dcipher.doFinal(dec);
    a=new String(utf8,"UTF8");
    dec=new Base64().decode(consumerSecret);
    utf8=dcipher.doFinal(dec);
    b=new String(utf8,"UTF8");
  }
 catch (  Exception ex) {
    Exceptions.printStackTrace(ex);
  }
}
 

Example 43

From project eucalyptus, under directory /clc/modules/image-manager/src/edu/ucsb/eucalyptus/cloud/ws/.

Source file: ImageManager.java

  31 
vote

private void verifyManifestIntegrity(final ImageInfo imgInfo) throws EucalyptusCloudException {
  String[] imagePathParts=imgInfo.getImageLocation().split("/");
  GetObjectResponseType reply=null;
  GetObjectType msg=new GetObjectType(imagePathParts[0],imagePathParts[1],true,false,true);
  msg.setUserId(EucalyptusProperties.NAME);
  msg.setEffectiveUserId(EucalyptusProperties.NAME);
  try {
    reply=(GetObjectResponseType)Messaging.send(WalrusProperties.WALRUS_REF,msg);
  }
 catch (  EucalyptusCloudException e) {
    LOG.error(e);
    LOG.debug(e,e);
    throw new EucalyptusCloudException("Invalid manifest reference: " + imgInfo.getImageLocation());
  }
  if (reply == null || reply.getBase64Data() == null)   throw new EucalyptusCloudException("Invalid manifest reference: " + imgInfo.getImageLocation());
  XMLParser parser=new XMLParser(reply.getBase64Data());
  String encryptedKey=parser.getValue("//ec2_encrypted_key");
  String encryptedIV=parser.getValue("//ec2_encrypted_iv");
  String signature=parser.getValue("//signature");
  String image=parser.getXML("image");
  String machineConfiguration=parser.getXML("machine_configuration");
  EntityWrapper<UserInfo> db=new EntityWrapper<UserInfo>();
  List<String> aliases=Lists.newArrayList();
  List<UserInfo> users=db.query(new UserInfo());
  for (  UserInfo user : users)   for (  CertificateInfo certInfo : user.getCertificates())   aliases.add(certInfo.getCertAlias());
  boolean found=false;
  for (  String alias : aliases)   found|=this.verifyManifestSignature(signature,alias,machineConfiguration + image);
  if (!found)   throw new EucalyptusCloudException("Invalid Manifest: Failed to verify signature.");
  try {
    PrivateKey pk=(PrivateKey)UserKeyStore.getInstance().getKey(EucalyptusProperties.NAME,EucalyptusProperties.NAME);
    Cipher cipher=Cipher.getInstance("RSA/ECB/PKCS1Padding");
    cipher.init(Cipher.DECRYPT_MODE,pk);
    cipher.doFinal(Hashes.hexToBytes(encryptedKey));
    cipher.doFinal(Hashes.hexToBytes(encryptedIV));
  }
 catch (  Exception ex) {
    throw new EucalyptusCloudException("Invalid Manifest: Failed to recover keys.");
  }
}
 

Example 44

From project evodroid, under directory /src/com/sonorth/evodroid/.

Source file: b2evolutionDB.java

  31 
vote

public static String encryptPassword(String clearText){
  try {
    DESKeySpec keySpec=new DESKeySpec(PASSWORD_SECRET.getBytes("UTF-8"));
    SecretKeyFactory keyFactory=SecretKeyFactory.getInstance("DES");
    SecretKey key=keyFactory.generateSecret(keySpec);
    Cipher cipher=Cipher.getInstance("DES");
    cipher.init(Cipher.ENCRYPT_MODE,key);
    String encrypedPwd=Base64.encodeBytes(cipher.doFinal(clearText.getBytes("UTF-8")));
    return encrypedPwd;
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
  return clearText;
}
 

Example 45

From project flume, under directory /flume-ng-channels/flume-file-channel/src/main/java/org/apache/flume/channel/file/encryption/.

Source file: AESCTRNoPaddingProvider.java

  31 
vote

private static Cipher getCipher(Key key,int mode,byte[] parameters){
  try {
    Cipher cipher=Cipher.getInstance(TYPE);
    cipher.init(mode,key,new IvParameterSpec(parameters));
    return cipher;
  }
 catch (  Exception e) {
    String msg="Unable to load key using transformation: " + TYPE;
    if (e instanceof InvalidKeyException) {
      try {
        int maxAllowedLen=Cipher.getMaxAllowedKeyLength(TYPE);
        if (maxAllowedLen < 256) {
          msg+="; Warning: Maximum allowed key length = " + maxAllowedLen + " with the available JCE security policy files. Have you"+ " installed the JCE unlimited strength jurisdiction policy"+ " files?";
        }
      }
 catch (      NoSuchAlgorithmException ex) {
        msg+="; Unable to find specified algorithm?";
      }
    }
    LOG.error(msg,e);
    throw Throwables.propagate(e);
  }
}
 

Example 46

From project GradeCalculator-Android, under directory /GradeCalculator/src/com/jetheis/android/grades/billing/.

Source file: Security.java

  31 
vote

private static String encryptUnlockKey(Context context,byte[] salt){
  Cipher encrypter;
  try {
    SecretKeyFactory factory=SecretKeyFactory.getInstance(KEYGEN_ALGORITHM);
    KeySpec keySpec=new PBEKeySpec(getPasswordForDevice(context),salt,1024,256);
    SecretKey tmp=factory.generateSecret(keySpec);
    SecretKey secret=new SecretKeySpec(tmp.getEncoded(),"AES");
    encrypter=Cipher.getInstance(CIPHER_ALGORITHM);
    encrypter.init(Cipher.ENCRYPT_MODE,secret,new IvParameterSpec(AES_IV));
  }
 catch (  GeneralSecurityException e) {
    throw new RuntimeException("Invalid environment",e);
  }
  try {
    return Base64.encodeToString(salt,Base64.NO_WRAP) + Base64.encodeToString(encrypter.doFinal(getUnlockKeyForDevice(context).getBytes("UTF-8")),Base64.NO_WRAP);
  }
 catch (  IllegalBlockSizeException e) {
    throw new RuntimeException("Encoding error",e);
  }
catch (  BadPaddingException e) {
    throw new RuntimeException("Encoding error",e);
  }
catch (  UnsupportedEncodingException e) {
    throw new RuntimeException("Invalid environment",e);
  }
}
 

Example 47

From project httpClient, under directory /httpclient/src/main/java/org/apache/http/impl/auth/.

Source file: NTLMEngineImpl.java

  31 
vote

/** 
 * Creates the LM Hash of the user's password.
 * @param password The password.
 * @return The LM Hash of the given password, used in the calculation of theLM Response.
 */
private static byte[] lmHash(String password) throws NTLMEngineException {
  try {
    byte[] oemPassword=password.toUpperCase().getBytes("US-ASCII");
    int length=Math.min(oemPassword.length,14);
    byte[] keyBytes=new byte[14];
    System.arraycopy(oemPassword,0,keyBytes,0,length);
    Key lowKey=createDESKey(keyBytes,0);
    Key highKey=createDESKey(keyBytes,7);
    byte[] magicConstant="KGS!@#$%".getBytes("US-ASCII");
    Cipher des=Cipher.getInstance("DES/ECB/NoPadding");
    des.init(Cipher.ENCRYPT_MODE,lowKey);
    byte[] lowHash=des.doFinal(magicConstant);
    des.init(Cipher.ENCRYPT_MODE,highKey);
    byte[] highHash=des.doFinal(magicConstant);
    byte[] lmHash=new byte[16];
    System.arraycopy(lowHash,0,lmHash,0,8);
    System.arraycopy(highHash,0,lmHash,8,8);
    return lmHash;
  }
 catch (  Exception e) {
    throw new NTLMEngineException(e.getMessage(),e);
  }
}
 

Example 48

From project hudson-test-harness, under directory /src/test/java/hudson/model/.

Source file: UsageStatisticsTest.java

  31 
vote

/** 
 * Makes sure that the stat data can be decrypted safely.
 */
public void testRoundtrip() throws Exception {
  String privateKey="30820276020100300d06092a864886f70d0101010500048202603082025c0201000281810084cababdb38040f659c2cb07a36d758f46e84ebc3d6ba39d967aedf1d396b0788ed3ab868d45ce280b1102b434c2a250ddc3254defe1785ab4f94d7038cf69ecca16753d2de3f6ad8976b3f74902d8634111d730982da74e1a6e3fc0bc3523bba53e45b8a8cbfd0321b94efc9f7fefbe66ad85281e3d0323d87f4426ec51204f0203010001028180784deaacdea8bd31f2d44578601954be3f714b93c2d977dbd76efb8f71303e249ad12dbeb2d2a1192a1d7923a6010768d7e06a3597b3df83de1d5688eb0f0e58c76070eddd696682730c93890dc727564c65dc8416bfbde5aad4eb7a97ed923efb55a291daf3c00810c0e43851298472fd539aab355af8cedcf1e9a0cbead661024100c498375102b068806c71dec838dc8dfa5624fb8a524a49cffadc19d10689a8c9c26db514faba6f96e50a605122abd3c9af16e82f2b7565f384528c9f31ea5947024100aceafd31d7f4872a873c7e5fe88f20c2fb086a053c6970026b3ce364768e2033100efb1ad8f2010fe53454a29decedc23a8a0c8df347742b1f13e11bd3a284b9024100931321470cd0f6cd24d4278bf8e61f9d69b6ef2bf3163a944aa340f91c7ffdf33aeea22b18cc43514af6714a21bb148d6cdca14530a8fa65acd7a8f62bfc9b5f024067452059f8438dc61466488336fce3f00ec483ad04db638dce45daf850e5a8cd5635dc39b87f2fab32940247ec5167ddabe06e870858104500967ac687aa73e102407e3b7997503e18d8d0f094d5e0bd5d57cb93cb39a2fc42cec1ea9a1562786438b61139e45813204d72c919f5397e139ad051d98e4d0f8a06d237f42c0d8440fb";
  String publicKey="30819f300d06092a864886f70d010101050003818d003081890281810084cababdb38040f659c2cb07a36d758f46e84ebc3d6ba39d967aedf1d396b0788ed3ab868d45ce280b1102b434c2a250ddc3254defe1785ab4f94d7038cf69ecca16753d2de3f6ad8976b3f74902d8634111d730982da74e1a6e3fc0bc3523bba53e45b8a8cbfd0321b94efc9f7fefbe66ad85281e3d0323d87f4426ec51204f0203010001";
  String data=new UsageStatistics(publicKey).getStatData();
  System.out.println(data);
  KeyFactory keyFactory=KeyFactory.getInstance("RSA");
  PrivateKey priv=keyFactory.generatePrivate(new PKCS8EncodedKeySpec(Util.fromHexString(privateKey)));
  Cipher cipher=Cipher.getInstance("RSA");
  cipher.init(Cipher.DECRYPT_MODE,priv);
  byte[] cipherText=Base64.decode(data.toCharArray());
  InputStreamReader r=new InputStreamReader(new GZIPInputStream(new CombinedCipherInputStream(new ByteArrayInputStream(cipherText),cipher,"AES",1024)),"UTF-8");
  JSONObject o=JSONObject.fromObject(IOUtils.toString(r));
  System.out.println(o);
  assertEquals(1,o.getInt("stat"));
}
 

Example 49

From project java-cas-client, under directory /cas-client-core/src/main/java/org/jasig/cas/client/proxy/.

Source file: AbstractEncryptedProxyGrantingTicketStorageImpl.java

  31 
vote

private String encrypt(final String value){
  if (this.key == null) {
    return value;
  }
  if (value == null) {
    return null;
  }
  try {
    final Cipher cipher=Cipher.getInstance(this.cipherAlgorithm);
    cipher.init(Cipher.ENCRYPT_MODE,this.key);
    return new String(cipher.doFinal(value.getBytes()));
  }
 catch (  final Exception e) {
    throw new RuntimeException(e);
  }
}
 

Example 50

From project JavaStory, under directory /Core/src/main/java/javastory/client/.

Source file: LoginCrypto.java

  31 
vote

public static String decryptRSA(final String EncryptedPassword){
  try {
    final Cipher cipher=Cipher.getInstance("RSA/NONE/OAEPPadding","BC");
    final BigInteger modulus=new BigInteger("107657795738756861764863218740655861479186575385923787150128619142132921674398952720882614694082036467689482295621654506166910217557126105160228025353603544726428541751588805629215516978192030682053419499436785335057001573080195806844351954026120773768050428451512387703488216884037312069441551935633523181351");
    final BigInteger privateExponent=new BigInteger("5550691850424331841608142211646492148529402295329912519344562675759756203942720314385192411176941288498447604817211202470939921344057999440566557786743767752684118754789131428284047255370747277972770485804010629706937510833543525825792410474569027516467052693380162536113699974433283374142492196735301185337");
    final RSAPrivateKeySpec privKey1=new RSAPrivateKeySpec(modulus,privateExponent);
    final PrivateKey privKey=RSAKeyFactory.generatePrivate(privKey1);
    final byte[] bytes=Hex.decode(EncryptedPassword);
    cipher.init(Cipher.DECRYPT_MODE,privKey);
    return new String(cipher.doFinal(bytes));
  }
 catch (  final InvalidKeyException ike) {
    System.err.println("[LoginCrypto] Error initalizing the encryption cipher.  Make sure you're using the Unlimited Strength cryptography jar files.");
  }
catch (  final NoSuchProviderException nspe) {
    System.err.println("[LoginCrypto] Security provider not found");
  }
catch (  final Exception e) {
    System.err.println("[LoginCrypto] Error occured with RSA password decryption.");
  }
  return "";
}
 

Example 51

From project jftp, under directory /src/main/java/com/myjavaworld/jftp/.

Source file: FavoritesManager.java

  31 
vote

/** 
 * Saves the given list of favourite FTP sites to the favorite file.
 * @param favorites List of favorites to be searialized
 * @exception IOException if an IO error occurs
 */
public static void saveFavorites(List favorites) throws IOException, IllegalBlockSizeException {
  if (favorites == null) {
    favorites=new ArrayList();
  }
  checkDataHome();
  ObjectOutputStream out=null;
  try {
    out=new ObjectOutputStream(new FileOutputStream(FAV_FILE));
    Cipher cipher=getCipher(Cipher.ENCRYPT_MODE);
    if (cipher == null) {
      out.writeObject(favorites);
    }
 else {
      SealedObject so=new SealedObject((Serializable)favorites,cipher);
      out.writeObject(so);
    }
  }
  finally {
    if (out != null) {
      out.close();
    }
    out=null;
  }
}
 

Example 52

From project JGit, under directory /org.spearce.jgit/src/org/spearce/jgit/transport/.

Source file: WalkEncryption.java

  31 
vote

@Override OutputStream encrypt(final OutputStream os) throws IOException {
  try {
    final Cipher c=Cipher.getInstance(algorithmName);
    c.init(Cipher.ENCRYPT_MODE,skey,aspec);
    return new CipherOutputStream(os,c);
  }
 catch (  NoSuchAlgorithmException e) {
    throw error(e);
  }
catch (  NoSuchPaddingException e) {
    throw error(e);
  }
catch (  InvalidKeyException e) {
    throw error(e);
  }
catch (  InvalidAlgorithmParameterException e) {
    throw error(e);
  }
}
 

Example 53

From project jOryx_1, under directory /src/com/oryxhatesjava/util/.

Source file: GUID.java

  31 
vote

public static String encrypt(String string){
  byte[] buf=stringToBytes(string);
  if (key == null) {
    try {
      X509EncodedKeySpec spec=new X509EncodedKeySpec(Base64.decode(serverPublicKey));
      KeyFactory kf=KeyFactory.getInstance("RSA");
      key=kf.generatePublic(spec);
    }
 catch (    Exception e) {
      e.printStackTrace();
      return null;
    }
  }
  try {
    Cipher cipher=Cipher.getInstance("RSA");
    cipher.init(Cipher.ENCRYPT_MODE,key);
    buf=cipher.doFinal(buf);
    return Base64.encodeBytes(buf);
  }
 catch (  Exception e) {
    key=null;
    e.printStackTrace();
    return null;
  }
}
 

Example 54

From project jPOS, under directory /jpos/src/main/java/org/jpos/security/jceadapter/.

Source file: JCEHandler.java

  31 
vote

/** 
 * performs cryptographic operations (encryption/decryption) using JCE Cipher
 * @param data
 * @param key
 * @param CipherMode Cipher.ENCRYPT_MODE or Cipher.DECRYPT_MODE
 * @return result of the cryptographic operations
 * @throws JCEHandlerException
 */
byte[] doCryptStuff(byte[] data,Key key,int CipherMode,String desMode,byte[] iv) throws JCEHandlerException {
  byte[] result;
  String transformation;
  if (key.getAlgorithm().startsWith(ALG_DES)) {
    transformation=key.getAlgorithm() + "/" + desMode+ "/"+ DES_NO_PADDING;
  }
 else {
    transformation=key.getAlgorithm();
  }
  AlgorithmParameterSpec aps=null;
  try {
    Cipher c1=Cipher.getInstance(transformation,provider.getName());
    if (DES_MODE_CBC.equals(desMode))     aps=new IvParameterSpec(iv);
    c1.init(CipherMode,key,aps);
    result=c1.doFinal(data);
  }
 catch (  Exception e) {
    throw new JCEHandlerException(e);
  }
  return result;
}
 

Example 55

From project jreepad, under directory /src/jreepad/io/.

Source file: EncryptedReader.java

  31 
vote

public JreepadTreeModel read(InputStream in) throws IOException {
  while (in.read() != '\n')   ;
  Cipher cipher=null;
  try {
    cipher=Cipher.getInstance(EncryptedWriter.ALGORITHM);
    Key key=new SecretKeySpec(password.getBytes(),EncryptedWriter.ALGORITHM);
    cipher.init(Cipher.DECRYPT_MODE,key);
  }
 catch (  GeneralSecurityException e) {
    throw new IOException(e.toString());
  }
  InputStream in2=new CipherInputStream(in,cipher);
  JreepadTreeModel document;
  try {
    document=reader.read(in2);
  }
 catch (  IOException e) {
    throw new IOException("Password incorrect or read problem occurred");
  }
  document.setFileType(JreepadPrefs.FILETYPE_XML_ENCRYPTED);
  document.setPassword(password);
  return document;
}
 

Example 56

From project nevernote, under directory /src/cx/fbn/nevernote/evernote/.

Source file: EnCrypt.java

  31 
vote

public String encrypt(String text,String passphrase,int keylen){
  RC2ParameterSpec parm=new RC2ParameterSpec(keylen);
  try {
    MessageDigest md=MessageDigest.getInstance("MD5");
    md.update(passphrase.getBytes(getCharset()));
    SecretKeySpec skeySpec=new SecretKeySpec(md.digest(),"RC2");
    Cipher cipher=Cipher.getInstance("RC2/ECB/NoPadding");
    cipher.init(Cipher.ENCRYPT_MODE,skeySpec,parm);
    byte[] newBytes=encodeStringNew(text);
    byte[] d=cipher.doFinal(newBytes);
    return Base64.encodeBytes(d);
  }
 catch (  NoSuchAlgorithmException e) {
    e.printStackTrace();
  }
catch (  NoSuchPaddingException e) {
    e.printStackTrace();
  }
catch (  InvalidKeyException e) {
    e.printStackTrace();
  }
catch (  InvalidAlgorithmParameterException e) {
    e.printStackTrace();
  }
catch (  IllegalBlockSizeException e) {
    e.printStackTrace();
  }
catch (  BadPaddingException e) {
    e.printStackTrace();
  }
  return null;
}
 

Example 57

From project openengsb-framework, under directory /components/util/src/main/java/org/openengsb/core/util/.

Source file: CipherUtils.java

  31 
vote

/** 
 * Decrypts the given data using the given key using the given algorithm. If you are decrypting data that is supposed to be a string, consider that it might be Base64-encoded.
 * @throws DecryptionException if the string cannot be decrypted with the given key
 * @throws IllegalArgumentException if the algorithm is not supported.
 */
public static byte[] decrypt(byte[] text,Key key,String algorithm) throws DecryptionException {
  Cipher cipher;
  try {
    LOGGER.trace("start decrypting text using {} cipher",algorithm);
    cipher=Cipher.getInstance(algorithm);
    cipher.init(Cipher.DECRYPT_MODE,key);
    LOGGER.trace("initialized decryption with key of type {}",key.getClass());
  }
 catch (  GeneralSecurityException e) {
    throw new IllegalArgumentException("unable to initialize cipher for algorithm " + algorithm,e);
  }
  try {
    return cipher.doFinal(text);
  }
 catch (  GeneralSecurityException e) {
    throw new DecryptionException("unable to decrypt data using algorithm " + algorithm,e);
  }
}
 

Example 58

From project AirReceiver, under directory /src/main/java/org/phlo/AirReceiver/.

Source file: AirTunesCrytography.java

  29 
vote

/** 
 * Creates a  {@link javax.crypto.Cipher} instance from a {@link javax.crypto.CipherSpi}.
 * @param cipherSpi the {@link javax.cyrpto.CipherSpi} instance
 * @param transformation the transformation cipherSpi was obtained for
 * @return a {@link javax.crypto.Cipher} instance
 * @throws Throwable in case of an error
 */
private static Cipher getCipher(final CipherSpi cipherSpi,final String transformation) throws Throwable {
  final Class<Cipher> cipherClass=Cipher.class;
  final Constructor<Cipher> cipherConstructor=cipherClass.getDeclaredConstructor(CipherSpi.class,String.class);
  cipherConstructor.setAccessible(true);
  try {
    return cipherConstructor.newInstance(cipherSpi,transformation);
  }
 catch (  final InvocationTargetException e) {
    throw e.getCause();
  }
}
 

Example 59

From project android-client, under directory /xwiki-android-core/src/org/xwiki/android/security/.

Source file: Master.java

  29 
vote

public Master(){
  masterKey=getMasterKey();
  try {
    masterCipher=Cipher.getInstance("AES/ECB/PKCS7Padding");
  }
 catch (  NoSuchAlgorithmException e) {
    Log.e(TAG,"ENC algo missing: pwds will be saved in plaintext",e);
  }
catch (  NoSuchPaddingException e) {
    Log.e(TAG,"Padding scheme missing: pwds will be saved in plaintext",e);
  }
}
 

Example 60

From project AndroidBillingLibrary, under directory /AndroidBillingLibrary/src/net/robotmedia/billing/utils/.

Source file: AESObfuscator.java

  29 
vote

public AESObfuscator(byte[] salt,String password){
  try {
    SecretKeyFactory factory=SecretKeyFactory.getInstance(KEYGEN_ALGORITHM);
    KeySpec keySpec=new PBEKeySpec(password.toCharArray(),salt,1024,256);
    SecretKey tmp=factory.generateSecret(keySpec);
    SecretKey secret=new SecretKeySpec(tmp.getEncoded(),"AES");
    mEncryptor=Cipher.getInstance(CIPHER_ALGORITHM);
    mEncryptor.init(Cipher.ENCRYPT_MODE,secret,new IvParameterSpec(IV));
    mDecryptor=Cipher.getInstance(CIPHER_ALGORITHM);
    mDecryptor.init(Cipher.DECRYPT_MODE,secret,new IvParameterSpec(IV));
  }
 catch (  GeneralSecurityException e) {
    throw new RuntimeException("Invalid environment",e);
  }
}
 

Example 61

From project BazaarUtils, under directory /src/com/android/vending/licensing/.

Source file: AESObfuscator.java

  29 
vote

/** 
 * @param salt an array of random bytes to use for each (un)obfuscation
 * @param applicationId application identifier, e.g. the package name
 * @param deviceId device identifier. Use as many sources as possible tocreate this unique identifier.
 */
public AESObfuscator(byte[] salt,String applicationId,String deviceId){
  try {
    SecretKeyFactory factory=SecretKeyFactory.getInstance(KEYGEN_ALGORITHM);
    KeySpec keySpec=new PBEKeySpec((applicationId + deviceId).toCharArray(),salt,1024,256);
    SecretKey tmp=factory.generateSecret(keySpec);
    SecretKey secret=new SecretKeySpec(tmp.getEncoded(),"AES");
    mEncryptor=Cipher.getInstance(CIPHER_ALGORITHM);
    mEncryptor.init(Cipher.ENCRYPT_MODE,secret,new IvParameterSpec(IV));
    mDecryptor=Cipher.getInstance(CIPHER_ALGORITHM);
    mDecryptor.init(Cipher.DECRYPT_MODE,secret,new IvParameterSpec(IV));
  }
 catch (  GeneralSecurityException e) {
    throw new RuntimeException("Invalid environment",e);
  }
}
 

Example 62

From project core_4, under directory /impl/src/main/java/org/ajax4jsf/util/base64/.

Source file: Codec.java

  29 
vote

/** 
 * @param p
 * @throws java.security.InvalidKeyException
 * @throws java.io.UnsupportedEncodingException
 * @throws java.security.spec.InvalidKeySpecException
 * @throws java.security.NoSuchAlgorithmException
 * @throws javax.crypto.NoSuchPaddingException
 */
public void setPassword(String p) throws FacesException {
  byte[] s={(byte)0xA9,(byte)0x9B,(byte)0xC8,(byte)0x32,(byte)0x56,(byte)0x34,(byte)0xE3,(byte)0x03};
  try {
    KeySpec keySpec=new DESKeySpec(p.getBytes("UTF8"));
    SecretKey key=SecretKeyFactory.getInstance("DES").generateSecret(keySpec);
    e=Cipher.getInstance(key.getAlgorithm());
    d=Cipher.getInstance(key.getAlgorithm());
    e.init(Cipher.ENCRYPT_MODE,key);
    d.init(Cipher.DECRYPT_MODE,key);
  }
 catch (  Exception e) {
    throw new FacesException("Error set encryption key",e);
  }
}
 

Example 63

From project cp-common-utils, under directory /src/com/clarkparsia/common/io/.

Source file: EncryptedFile.java

  29 
vote

/** 
 * Initialize the ciphers based on the given secret key
 * @param theKey the key to use to create the ciphers
 */
private void initCiphers(SecretKey theKey){
  AlgorithmParameterSpec aSpec=new IvParameterSpec(IV);
  try {
    mEncryptCipher=Cipher.getInstance("DES/CBC/PKCS5Padding");
    mEncryptCipher.init(Cipher.ENCRYPT_MODE,theKey,aSpec);
    mDecryptCipher=createDecryptCipher(theKey);
  }
 catch (  java.security.InvalidAlgorithmParameterException e) {
    throw new IllegalStateException(e);
  }
catch (  javax.crypto.NoSuchPaddingException e) {
    throw new IllegalStateException(e);
  }
catch (  java.security.NoSuchAlgorithmException e) {
    throw new IllegalStateException(e);
  }
catch (  java.security.InvalidKeyException e) {
    throw new IllegalStateException(e);
  }
}
 

Example 64

From project flazr, under directory /src/main/java/com/flazr/rtmp/.

Source file: RtmpHandshake.java

  29 
vote

private void cipherUpdate(final ChannelBuffer in,final Cipher cipher){
  final int size=in.readableBytes();
  if (size == 0) {
    return;
  }
  final int position=in.readerIndex();
  final byte[] bytes=new byte[size];
  in.getBytes(position,bytes);
  in.setBytes(position,cipher.update(bytes));
}
 

Example 65

From project freemind, under directory /freemind/freemind/main/.

Source file: Tools.java

  29 
vote

/** 
 */
private void init(byte[] mSalt){
  if (mSalt != null) {
    this.salt=mSalt;
  }
  if (ecipher == null) {
    try {
      KeySpec keySpec=new PBEKeySpec(passPhrase,salt,iterationCount);
      SecretKey key=SecretKeyFactory.getInstance(mAlgorithm).generateSecret(keySpec);
      ecipher=Cipher.getInstance(mAlgorithm);
      dcipher=Cipher.getInstance(mAlgorithm);
      AlgorithmParameterSpec paramSpec=new PBEParameterSpec(salt,iterationCount);
      ecipher.init(Cipher.ENCRYPT_MODE,key,paramSpec);
      dcipher.init(Cipher.DECRYPT_MODE,key,paramSpec);
    }
 catch (    java.security.InvalidAlgorithmParameterException e) {
    }
catch (    java.security.spec.InvalidKeySpecException e) {
    }
catch (    javax.crypto.NoSuchPaddingException e) {
    }
catch (    java.security.NoSuchAlgorithmException e) {
    }
catch (    java.security.InvalidKeyException e) {
    }
  }
}
 

Example 66

From project Gmote, under directory /gmoteserver/src/org/gmote/server/.

Source file: StringEncrypter.java

  29 
vote

public StringEncrypter() throws UnsupportedEncodingException, InvalidKeyException, NoSuchAlgorithmException, NoSuchPaddingException {
  byte[] keyAsBytes=SECRET.getBytes(UNICODE_FORMAT);
  keySpec=new DESKeySpec(keyAsBytes);
  keyFactory=SecretKeyFactory.getInstance(DES_NAME);
  cipher=Cipher.getInstance(DES_NAME);
}
 

Example 67

From project greenhouse, under directory /src/main/java/com/springsource/greenhouse/database/upgrade/v3/.

Source file: CipherUtils.java

  29 
vote

public static Cipher newCipher(String algorithm){
  try {
    return Cipher.getInstance(algorithm);
  }
 catch (  NoSuchAlgorithmException e) {
    throw new IllegalArgumentException("Not a valid encryption algorithm",e);
  }
catch (  NoSuchPaddingException e) {
    throw new IllegalStateException("Should not happen",e);
  }
}
 

Example 68

From project hdiv, under directory /hdiv-core/src/main/java/org/hdiv/cipher/.

Source file: CipherHTTP.java

  29 
vote

/** 
 * Generates a Cipher object that implements the specified transformation.
 */
public void init(){
  try {
    if (this.provider == null) {
      this.cipher=Cipher.getInstance(this.transformation);
    }
 else {
      this.cipher=Cipher.getInstance(this.transformation,this.provider);
    }
  }
 catch (  NoSuchProviderException e) {
    throw new HDIVException(e.getMessage());
  }
catch (  NoSuchAlgorithmException e) {
    throw new HDIVException(e.getMessage());
  }
catch (  NoSuchPaddingException e) {
    throw new HDIVException(e.getMessage());
  }
}
 

Example 69

From project JavaJunction, under directory /src/main/java/edu/stanford/junction/extra/.

Source file: Encryption.java

  29 
vote

private void init(){
  try {
    mCipher=Cipher.getInstance("AES/CBC/PKCS5PADDING");
    mKeySpec=new SecretKeySpec(mKey,"AES");
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}
 

Example 70

From project jboss-sasl, under directory /src/main/java/org/jboss/sasl/digest/.

Source file: DigestMD5Base.java

  29 
vote

protected static byte[] getPlatformCiphers(){
  byte[] ciphers=new byte[CIPHER_TOKENS.length];
  for (int i=0; i < JCE_CIPHER_NAME.length; i++) {
    try {
      Cipher.getInstance(JCE_CIPHER_NAME[i]);
      log.tracef("Platform supports %s",JCE_CIPHER_NAME[i]);
      ciphers[i]|=CIPHER_MASKS[i];
    }
 catch (    NoSuchAlgorithmException e) {
    }
catch (    NoSuchPaddingException e) {
    }
  }
  if (ciphers[RC4] != UNSET) {
    ciphers[RC4_56]|=CIPHER_MASKS[RC4_56];
    ciphers[RC4_40]|=CIPHER_MASKS[RC4_40];
  }
  return ciphers;
}
 

Example 71

From project JDBM3, under directory /src/main/java/org/apache/jdbm/.

Source file: DBCacheRef.java

  29 
vote

/** 
 * Construct a CacheRecordManager wrapping another DB and using a given cache policy.
 */
public DBCacheRef(String filename,boolean readonly,boolean transactionDisabled,Cipher cipherIn,Cipher cipherOut,boolean useRandomAccessFile,boolean deleteFilesAfterClose,byte cacheType,boolean cacheAutoClearOnLowMem,boolean lockingDisabled){
  super(filename,readonly,transactionDisabled,cipherIn,cipherOut,useRandomAccessFile,deleteFilesAfterClose,lockingDisabled);
  this._cacheType=cacheType;
  _autoClearReferenceCacheOnLowMem=cacheAutoClearOnLowMem;
  _softHash=new LongHashMap<ReferenceCacheEntry>();
  _refQueue=new ReferenceQueue<ReferenceCacheEntry>();
  _softRefThread=new Thread(new SoftRunnable(this,_refQueue),"JDBM Soft Cache Disposer " + (threadCounter.incrementAndGet()));
  _softRefThread.setDaemon(true);
  _softRefThread.start();
}
 

Example 72

From project jira-hudson-integration, under directory /jira-hudson-plugin/src/main/java/com/marvelution/jira/plugins/hudson/encryption/.

Source file: StringEncrypter.java

  29 
vote

/** 
 * Constructor
 */
public StringEncrypter(){
  try {
    keySpec=new DESedeKeySpec(DEFAULT_ENCRYPTION_KEY.getBytes(UNICODE_FORMAT));
    keyFactory=SecretKeyFactory.getInstance(DESEDE_ENCRYPTION_SCHEME);
    cipher=Cipher.getInstance(DESEDE_ENCRYPTION_SCHEME);
  }
 catch (  Exception e) {
    LOGGER.fatal("Failed to initilise String Encryption classes. Reason: " + e.getMessage(),e);
    throw new StringEncryptionException("Failed to initilise String Encryption classes. Reason: " + e.getMessage(),e);
  }
}
 

Example 73

From project LVLPractice, under directory /src/com/android/vending/licensing/.

Source file: AESObfuscator.java

  29 
vote

/** 
 * @param salt an array of random bytes to use for each (un)obfuscation
 * @param applicationId application identifier, e.g. the package name
 * @param deviceId device identifier. Use as many sources as possible to create this unique identifier.
 */
public AESObfuscator(byte[] salt,String applicationId,String deviceId){
  try {
    SecretKeyFactory factory=SecretKeyFactory.getInstance(KEYGEN_ALGORITHM);
    KeySpec keySpec=new PBEKeySpec((applicationId + deviceId).toCharArray(),salt,1024,256);
    SecretKey tmp=factory.generateSecret(keySpec);
    SecretKey secret=new SecretKeySpec(tmp.getEncoded(),"AES");
    mEncryptor=Cipher.getInstance(CIPHER_ALGORITHM);
    mEncryptor.init(Cipher.ENCRYPT_MODE,secret,new IvParameterSpec(IV));
    mDecryptor=Cipher.getInstance(CIPHER_ALGORITHM);
    mDecryptor.init(Cipher.DECRYPT_MODE,secret,new IvParameterSpec(IV));
  }
 catch (  GeneralSecurityException e) {
    throw new RuntimeException("Invalid environment",e);
  }
}
 

Example 74

From project milton, under directory /milton/milton-client-app/src/main/java/bradswebdavclient/.

Source file: StringEncrypter.java

  29 
vote

public StringEncrypter(String encryptionScheme,String encryptionKey) throws EncryptionException {
  if (encryptionKey == null)   throw new IllegalArgumentException("encryption key was null");
  if (encryptionKey.trim().length() < 24)   throw new IllegalArgumentException("encryption key was less than 24 characters");
  try {
    byte[] keyAsBytes=encryptionKey.getBytes(UNICODE_FORMAT);
    if (encryptionScheme.equals(DESEDE_ENCRYPTION_SCHEME)) {
      keySpec=new DESedeKeySpec(keyAsBytes);
    }
 else     if (encryptionScheme.equals(DES_ENCRYPTION_SCHEME)) {
      keySpec=new DESKeySpec(keyAsBytes);
    }
 else {
      throw new IllegalArgumentException("Encryption scheme not supported: " + encryptionScheme);
    }
    keyFactory=SecretKeyFactory.getInstance(encryptionScheme);
    cipher=Cipher.getInstance(encryptionScheme);
  }
 catch (  InvalidKeyException e) {
    throw new EncryptionException(e);
  }
catch (  UnsupportedEncodingException e) {
    throw new EncryptionException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new EncryptionException(e);
  }
catch (  NoSuchPaddingException e) {
    throw new EncryptionException(e);
  }
}
 

Example 75

From project milton2, under directory /milton-client-app/src/main/java/bradswebdavclient/.

Source file: StringEncrypter.java

  29 
vote

public StringEncrypter(String encryptionScheme,String encryptionKey) throws EncryptionException {
  if (encryptionKey == null)   throw new IllegalArgumentException("encryption key was null");
  if (encryptionKey.trim().length() < 24)   throw new IllegalArgumentException("encryption key was less than 24 characters");
  try {
    byte[] keyAsBytes=encryptionKey.getBytes(UNICODE_FORMAT);
    if (encryptionScheme.equals(DESEDE_ENCRYPTION_SCHEME)) {
      keySpec=new DESedeKeySpec(keyAsBytes);
    }
 else     if (encryptionScheme.equals(DES_ENCRYPTION_SCHEME)) {
      keySpec=new DESKeySpec(keyAsBytes);
    }
 else {
      throw new IllegalArgumentException("Encryption scheme not supported: " + encryptionScheme);
    }
    keyFactory=SecretKeyFactory.getInstance(encryptionScheme);
    cipher=Cipher.getInstance(encryptionScheme);
  }
 catch (  InvalidKeyException e) {
    throw new EncryptionException(e);
  }
catch (  UnsupportedEncodingException e) {
    throw new EncryptionException(e);
  }
catch (  NoSuchAlgorithmException e) {
    throw new EncryptionException(e);
  }
catch (  NoSuchPaddingException e) {
    throw new EncryptionException(e);
  }
}
 

Example 76

From project mina-sshd, under directory /sshd-core/src/main/java/org/apache/sshd/common/util/.

Source file: SecurityUtils.java

  29 
vote

public static synchronized Cipher getCipher(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException, NoSuchProviderException {
  register();
  if (getSecurityProvider() == null) {
    return Cipher.getInstance(transformation);
  }
 else {
    return Cipher.getInstance(transformation,getSecurityProvider());
  }
}
 

Example 77

From project Openbravo-POS-iPhone-App, under directory /OpenbravoPOS_PDA/src-pda/com/openbravo/pos/pda/util/.

Source file: CryptUtils.java

  29 
vote

/** 
 * Creates a new instance of Encrypter 
 */
public CryptUtils(String passPhrase){
  try {
    SecureRandom sr=SecureRandom.getInstance("SHA1PRNG");
    sr.setSeed(passPhrase.getBytes("UTF8"));
    KeyGenerator kGen=KeyGenerator.getInstance("DESEDE");
    kGen.init(168,sr);
    Key key=kGen.generateKey();
    cipherDecrypt=Cipher.getInstance("DESEDE/ECB/PKCS5Padding");
    cipherDecrypt.init(Cipher.DECRYPT_MODE,key);
  }
 catch (  UnsupportedEncodingException e) {
  }
catch (  NoSuchPaddingException e) {
  }
catch (  NoSuchAlgorithmException e) {
  }
catch (  InvalidKeyException e) {
  }
}