コード例 #1
0
  private static SecretKey generateSymmetricKey() throws Exception {
    KeyGenerator generator = KeyGenerator.getInstance(KEY_ALGORITHM);
    SecureRandom random = new SecureRandom();
    generator.init(KEY_LENGTH_BITS, random);
    logger.debug("Generate Key");
    return generator.generateKey();
    // return new SecretKeySpec(Hex.decodeHex("cb024600dce7148b8ddc5d6c111fbd85".toCharArray()),
    // KEY_ALGORITHM);

  }
コード例 #2
0
  public void generate_new_aes_key() {

    try {
      KeyGenerator localKeyGenerator = KeyGenerator.getInstance("AES");
      localKeyGenerator.init(128, SecureRandom.getInstance("SHA1PRNG"));
      //        aes_key = Base64.encodeBase64String(localKeyGenerator.generateKey().getEncoded());
      aes_key =
          new String(Base64.encode(localKeyGenerator.generateKey().getEncoded(), Base64.DEFAULT));
    } catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
      System.out.println(localNoSuchAlgorithmException);
    }
    return;
  }
コード例 #3
0
ファイル: QuickCipher.java プロジェクト: Blir/BlirLibrary
 /**
  * Constructs a new QuickChipher with the given transformation and algorithm.
  *
  * @param transformation the transformation to be used to create the Cipher for this QuickCipher.
  * @param algorithm the algorithm to be used to create the SecretKey for this QuickCipher.
  * @throws NoSuchAlgorithmException if transformation is null, empty, in an invalid format, or if
  *     no Provider supports a CipherSpi implementation for the specified algorithm or if no
  *     Provider supports a KeyGeneratorSpi implementation for the specified algorithm.
  * @throws NoSuchPaddingException if transformation contains a padding scheme that is not
  *     available.
  */
 public QuickCipher(String transformation, String algorithm)
     throws NoSuchAlgorithmException, NoSuchPaddingException {
   this.algorithm = algorithm;
   cipher = Cipher.getInstance(transformation);
   key = KeyGenerator.getInstance(this.algorithm).generateKey();
 }