Examples of BlockCipher


Examples of ch.ethz.ssh2.crypto.cipher.BlockCipher

    /* Tell the other side that we start using the new material */

    PacketNewKeys ign = new PacketNewKeys();
    tm.sendKexMessage(ign.getPayload());

    BlockCipher cbc;
    MAC mac;

    try
    {
      cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_client_to_server, true, km.enc_key_client_to_server,
View Full Code Here

Examples of ch.ethz.ssh2.crypto.cipher.BlockCipher

    if (msg[0] == Packets.SSH_MSG_NEWKEYS)
    {
      if (km == null)
        throw new IOException("Peer sent SSH_MSG_NEWKEYS, but I have no key material ready!");

      BlockCipher cbc;
      MAC mac;

      try
      {
        cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_server_to_client, false,
View Full Code Here

Examples of ch.ethz.ssh2.crypto.cipher.BlockCipher

      throw new IOException("Broken PEM, DEK-Info is incomplete!");

    String algo = ps.dekInfo[0];
    byte[] salt = hexToByteArray(ps.dekInfo[1]);

    BlockCipher bc = null;

    if (algo.equals("DES-EDE3-CBC"))
    {
      DESede des3 = new DESede();
      des3.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 24));
      bc = new CBCMode(des3, salt, false);
    }
    else if (algo.equals("DES-CBC"))
    {
      DES des = new DES();
      des.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 8));
      bc = new CBCMode(des, salt, false);
    }
    else if (algo.equals("AES-128-CBC"))
    {
      AES aes = new AES();
      aes.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 16));
      bc = new CBCMode(aes, salt, false);
    }
    else if (algo.equals("AES-192-CBC"))
    {
      AES aes = new AES();
      aes.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 24));
      bc = new CBCMode(aes, salt, false);
    }
    else if (algo.equals("AES-256-CBC"))
    {
      AES aes = new AES();
      aes.init(false, generateKeyFromPasswordSaltWithMD5(pw, salt, 32));
      bc = new CBCMode(aes, salt, false);
    }
    else
    {
      throw new IOException("Cannot decrypt PEM structure, unknown cipher " + algo);
    }

    if ((ps.data.length % bc.getBlockSize()) != 0)
      throw new IOException("Invalid PEM structure, size of encrypted block is not a multiple of "
          + bc.getBlockSize());

    /* Now decrypt the content */

    byte[] dz = new byte[ps.data.length];

    for (int i = 0; i < ps.data.length / bc.getBlockSize(); i++)
    {
      bc.transformBlock(ps.data, i * bc.getBlockSize(), dz, i * bc.getBlockSize());
    }

    /* Now check and remove RFC 1423/PKCS #7 padding */

    dz = removePadding(dz, bc.getBlockSize());

    ps.data = dz;
    ps.dekInfo = null;
    ps.procType = null;
  }
View Full Code Here

Examples of com.trilead.ssh2.crypto.cipher.BlockCipher

    /* Tell the other side that we start using the new material */

    PacketNewKeys ign = new PacketNewKeys();
    tm.sendKexMessage(ign.getPayload());

    BlockCipher cbc;
    MAC mac;

    try
    {
      cbc = BlockCipherFactory.createCipher(kxs.np.enc_algo_client_to_server, true, km.enc_key_client_to_server,
View Full Code Here

Examples of freenet.crypt.BlockCipher

                md.update(salt);
                md.update(outerKey);
                outerKey = md.digest();
            }
        }
        BlockCipher cipher;
        try {
          cipher = new Rijndael(256, 256);
        } catch (UnsupportedCipherException e) {
          // Impossible
          throw new Error(e);
        }
//        System.err.println("Outer key: "+HexUtil.bytesToHex(outerKey));
        cipher.initialize(outerKey);
        PCFBMode pcfb = PCFBMode.create(cipher, iv);
        pcfb.blockDecipher(dataAndHash, 0, dataAndHash.length);
//        System.err.println("Decrypted data and hash: "+HexUtil.bytesToHex(dataAndHash));
        byte[] data = Arrays.copyOf(dataAndHash, dataAndHash.length - HASH_LENGTH);
        byte[] hash = Arrays.copyOfRange(dataAndHash, data.length, dataAndHash.length);
View Full Code Here

Examples of freenet.crypt.BlockCipher

        byte[] pwd = password.getBytes("UTF-8");
        MessageDigest md = SHA256.getMessageDigest();
        md.update(pwd);
        md.update(salt);
        byte[] outerKey = md.digest();
        BlockCipher cipher;
        try {
            cipher = new Rijndael(256, 256);
        } catch (UnsupportedCipherException e) {
            // Impossible
            throw new Error(e);
        }
//      System.err.println("Outer key: "+HexUtil.bytesToHex(outerKey));
        cipher.initialize(outerKey);
        PCFBMode pcfb = PCFBMode.create(cipher, iv);
        pcfb.blockDecipher(dataAndHash, 0, dataAndHash.length);
//      System.err.println("Decrypted data and hash: "+HexUtil.bytesToHex(dataAndHash));
        byte[] data = Arrays.copyOf(dataAndHash, dataAndHash.length - OLD_HASH_LENGTH);
        byte[] hash = Arrays.copyOfRange(dataAndHash, data.length, dataAndHash.length);
View Full Code Here

Examples of freenet.crypt.BlockCipher

    byte[] hash = md.digest();
        SHA256.returnMessageDigest(md); md = null;
    baos.write(hash, 0, HASH_LENGTH);
    data = baos.toByteArray();

    BlockCipher cipher;
    try {
      cipher = new Rijndael(256, 256);
    } catch (UnsupportedCipherException e) {
      // Impossible
      throw new Error(e);
    }
    cipher.initialize(outerKey);
    PCFBMode pcfb = PCFBMode.create(cipher, iv);
    pcfb.blockEncipher(data, hashedStart, data.length - hashedStart);

    RandomAccessFile raf = new RandomAccessFile(masterKeysFile, "rw");
View Full Code Here

Examples of freenet.crypt.BlockCipher

    return null;
  }

  /** Must NOT modify buf contents. */
  private NPFPacket decipherFromSeqnum(byte[] buf, int offset, int length, SessionKey sessionKey, int sequenceNumber) {
    BlockCipher ivCipher = sessionKey.ivCipher;

    byte[] IV = new byte[ivCipher.getBlockSize() / 8];
    System.arraycopy(sessionKey.ivNonce, 0, IV, 0, IV.length);
    IV[IV.length - 4] = (byte) (sequenceNumber >>> 24);
    IV[IV.length - 3] = (byte) (sequenceNumber >>> 16);
    IV[IV.length - 2] = (byte) (sequenceNumber >>> 8);
    IV[IV.length - 1] = (byte) (sequenceNumber);

    ivCipher.encipher(IV, IV);

    byte[] payload = Arrays.copyOfRange(buf, offset + hmacLength, offset + length);
    byte[] hash = Arrays.copyOfRange(buf, offset, offset + hmacLength);

    if(!HMAC.verifyWithSHA256(sessionKey.hmacKey, payload, hash)) return null;
View Full Code Here

Examples of freenet.crypt.BlockCipher

    seqNumBytes[0] = (byte) (seqNum >>> 24);
    seqNumBytes[1] = (byte) (seqNum >>> 16);
    seqNumBytes[2] = (byte) (seqNum >>> 8);
    seqNumBytes[3] = (byte) (seqNum);

    BlockCipher ivCipher = sessionKey.ivCipher;

    byte[] IV = new byte[ivCipher.getBlockSize() / 8];
    System.arraycopy(sessionKey.ivNonce, 0, IV, 0, IV.length);
    System.arraycopy(seqNumBytes, 0, IV, IV.length - seqNumBytes.length, seqNumBytes.length);
    ivCipher.encipher(IV, IV);

    PCFBMode cipher = PCFBMode.create(sessionKey.incommingCipher, IV);
    cipher.blockEncipher(seqNumBytes, 0, seqNumBytes.length);

    return seqNumBytes;
View Full Code Here

Examples of freenet.crypt.BlockCipher

    }

    byte[] data = new byte[paddedLen];
    packet.toBytes(data, hmacLength, pn.paddingGen());

    BlockCipher ivCipher = sessionKey.ivCipher;

    byte[] IV = new byte[ivCipher.getBlockSize() / 8];
    System.arraycopy(sessionKey.ivNonce, 0, IV, 0, IV.length);
    System.arraycopy(data, hmacLength, IV, IV.length - 4, 4);

    ivCipher.encipher(IV, IV);

    PCFBMode payloadCipher = PCFBMode.create(sessionKey.outgoingCipher, IV);
    payloadCipher.blockEncipher(data, hmacLength, paddedLen - hmacLength);

    //Add hash
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.