Examples of SecretKeySpec


Examples of javax.crypto.spec.SecretKeySpec

   * @throws IOException if an error occurs
   */
  public static byte[] computeRFC2104HMAC(byte[] data, byte[] key) throws IOException {
     
      try {
          SecretKeySpec signingKey = new SecretKeySpec(key, "HmacSHA1");
   
          Mac mac = Mac.getInstance("HmacSHA1");
          mac.init(signingKey);
   
          byte[] rawHmac = mac.doFinal(data);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

        try {
            byte[] encodedKey =
                StringConverter.hexStringToByteArray(keyString);

            key       = new SecretKeySpec(encodedKey, cipherName);
            outCipher = provider == null ? Cipher.getInstance(cipherName)
                                         : Cipher.getInstance(cipherName,
                                         provider);

            outCipher.init(Cipher.ENCRYPT_MODE, key);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

            //Cipher encrypt = Cipher.getInstance("DES");           
            //SecretKey key = new SecretKeySpec(pass.getBytes(), "DES");
           
            Cipher encrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");

            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");

            encrypt.init(Cipher.ENCRYPT_MODE, key);

            // encode string mit utf8           
            byte[] utf8 = str.getBytes(SOSCrypt.charset);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

            //Cipher decrypt = Cipher.getInstance("DES");
            //SecretKey key = new SecretKeySpec(pass.getBytes(), "DES");
            Cipher decrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");

            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");

            decrypt.init(Cipher.DECRYPT_MODE, key);


            // decode base64 zu bytes                               
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

            //Cipher encrypt = Cipher.getInstance("DES");           
            //SecretKey key = new SecretKeySpec(pass.getBytes(), "DES");
           
            Cipher encrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");

            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");

            encrypt.init(Cipher.ENCRYPT_MODE, key);

            // encode string mit utf8           
            byte[] utf8 = str.getBytes(SOSProfileCrypt.charset);
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

          // nur f�r jre 1.3.x n�tig
            Provider bp = new org.bouncycastle.jce.provider.BouncyCastleProvider();
            Security.addProvider(bp);
           
            Cipher decrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");
            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");
            decrypt.init(Cipher.DECRYPT_MODE, key);
           
            // decode base64 zu bytes                               
            byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(str);
            // decrypt
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

      byte[] sharedSecret = getSharedSecret(outgoingPublicKey, keyAgreement);
      // create output cipher
      byte[] digestOut = calculateHMAC_SHA256(outgoingPublicKey, sharedSecret);
      try {
        cipherOut = Cipher.getInstance("RC4");
        cipherOut.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(digestOut, 0, 16, "RC4"));
      } catch (Exception e) {
        JFLog.log("Encryption cipher creation failed" + e);
      }
      // create input cipher
      byte[] digestIn = calculateHMAC_SHA256(incomingPublicKey, sharedSecret);
      try {
        cipherIn = Cipher.getInstance("RC4");
        cipherIn.init(Cipher.DECRYPT_MODE, new SecretKeySpec(digestIn, 0, 16, "RC4"));
      } catch (Exception e) {
        JFLog.log("Decryption cipher creation failed" + e);
      }
      // update 'encoder / decoder state' for the RC4 keys
      // both parties *pretend* as if handshake part 2 (1536 bytes) was encrypted
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   * @return hmac hashed bytes
   */
  public byte[] calculateHMAC_SHA256(byte[] input, byte[] key) {
    byte[] output = null;
    try {
      hmacSHA256.init(new SecretKeySpec(key, "HmacSHA256"));
      output = hmacSHA256.doFinal(input);
    } catch (InvalidKeyException e) {
      JFLog.log("Invalid key", e);
    }
    return output;
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

   * @return hmac hashed bytes
   */
  public byte[] calculateHMAC_SHA256(byte[] input, byte[] key, int length) {
    byte[] output = null;
    try {
      hmacSHA256.init(new SecretKeySpec(key, 0, length, "HmacSHA256"));
      output = hmacSHA256.doFinal(input);
    } catch (InvalidKeyException e) {
      JFLog.log("Invalid key", e);
    }
    return output;
View Full Code Here

Examples of javax.crypto.spec.SecretKeySpec

            //Cipher encrypt = Cipher.getInstance("DES");           
            //SecretKey key = new SecretKeySpec(pass.getBytes(), "DES");
           
            Cipher encrypt = Cipher.getInstance("DESede/ECB/NoPadding", "BC");

            SecretKey key = new SecretKeySpec(pass.getBytes(), "DESede");

            encrypt.init(Cipher.ENCRYPT_MODE, key);

            // encode string mit utf8           
            byte[] utf8 = str.getBytes(SOSCrypt.charset);
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.