Search in sources :

Example 86 with CipherInputStream

use of javax.crypto.CipherInputStream in project SKMCLauncher by SKCraft.

the class IdentityList method importLogins.

/**
 * Import old launcher settings.
 */
public void importLogins() {
    File file = new File(Launcher.getOfficialDataDir(), "lastlogin");
    if (!file.exists())
        return;
    DataInputStream in = null;
    try {
        Cipher cipher = Launcher.getInstance().getCipher(Cipher.DECRYPT_MODE, Identity.MOJANG_ENCRYPTION_PASSWORD);
        in = new DataInputStream(new CipherInputStream(new FileInputStream(file), cipher));
        String username = in.readUTF();
        String password = in.readUTF();
        if (username.trim().length() == 0) {
            return;
        }
        if (password.trim().length() == 0) {
            password = null;
        }
        remember(username, password);
    } catch (Throwable e) {
    } finally {
        LauncherUtils.close(in);
    }
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) Cipher(javax.crypto.Cipher) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 87 with CipherInputStream

use of javax.crypto.CipherInputStream in project Pix-Art-Messenger by kriztan.

the class AbstractConnectionManager method createInputStream.

public static Pair<InputStream, Integer> createInputStream(DownloadableFile file, boolean gcm) throws FileNotFoundException {
    FileInputStream is;
    int size;
    is = new FileInputStream(file);
    size = (int) file.getSize();
    if (file.getKey() == null) {
        return new Pair<InputStream, Integer>(is, size);
    }
    try {
        if (gcm) {
            AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
            cipher.init(true, new AEADParameters(new KeyParameter(file.getKey()), 128, file.getIv()));
            InputStream cis = new org.bouncycastle.crypto.io.CipherInputStream(is, cipher);
            return new Pair<>(cis, cipher.getOutputSize(size));
        } else {
            IvParameterSpec ips = new IvParameterSpec(file.getIv());
            Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");
            cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(file.getKey(), "AES"), ips);
            Log.d(Config.LOGTAG, "opening encrypted input stream");
            return new Pair<InputStream, Integer>(new CipherInputStream(is, cipher), (size / 16 + 1) * 16);
        }
    } catch (InvalidKeyException e) {
        return null;
    } catch (NoSuchAlgorithmException e) {
        return null;
    } catch (NoSuchPaddingException e) {
        return null;
    } catch (InvalidAlgorithmParameterException e) {
        return null;
    }
}
Also used : AESEngine(org.bouncycastle.crypto.engines.AESEngine) InvalidAlgorithmParameterException(java.security.InvalidAlgorithmParameterException) CipherInputStream(javax.crypto.CipherInputStream) CipherInputStream(javax.crypto.CipherInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) KeyParameter(org.bouncycastle.crypto.params.KeyParameter) NoSuchPaddingException(javax.crypto.NoSuchPaddingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) FileInputStream(java.io.FileInputStream) AEADParameters(org.bouncycastle.crypto.params.AEADParameters) SecretKeySpec(javax.crypto.spec.SecretKeySpec) IvParameterSpec(javax.crypto.spec.IvParameterSpec) Cipher(javax.crypto.Cipher) AEADBlockCipher(org.bouncycastle.crypto.modes.AEADBlockCipher) GCMBlockCipher(org.bouncycastle.crypto.modes.GCMBlockCipher) GCMBlockCipher(org.bouncycastle.crypto.modes.GCMBlockCipher) AEADBlockCipher(org.bouncycastle.crypto.modes.AEADBlockCipher) Pair(android.util.Pair)

Example 88 with CipherInputStream

use of javax.crypto.CipherInputStream in project LshUtils by SenhLinsh.

the class FileEncryptUtilsEx method decryptFile.

/**
 * AES算法解密文件
 *
 * @param rawKey   AES密钥
 * @param fromFile 被加密的文件
 * @param toFile   解密后文件
 */
public static void decryptFile(byte[] rawKey, File fromFile, File toFile) throws Exception {
    if (!fromFile.exists()) {
        throw new NullPointerException("文件不存在");
    }
    if (toFile.exists()) {
        toFile.delete();
    }
    SecretKeySpec skeySpec = new SecretKeySpec(rawKey, AES);
    Cipher cipher = Cipher.getInstance(AES);
    // 解密模式
    cipher.init(Cipher.DECRYPT_MODE, skeySpec);
    FileInputStream fis = new FileInputStream(fromFile);
    FileOutputStream fos = new FileOutputStream(toFile, true);
    byte[] buffer = new byte[512 * 1024 + 16];
    int offset;
    // 使用解密流来解密
    CipherInputStream cipherInputStream = new CipherInputStream(fis, cipher);
    while ((offset = cipherInputStream.read(buffer)) != -1) {
        fos.write(buffer, 0, offset);
        fos.flush();
    }
    fos.close();
    fis.close();
}
Also used : CipherInputStream(javax.crypto.CipherInputStream) SecretKeySpec(javax.crypto.spec.SecretKeySpec) FileOutputStream(java.io.FileOutputStream) Cipher(javax.crypto.Cipher) FileInputStream(java.io.FileInputStream)

Example 89 with CipherInputStream

use of javax.crypto.CipherInputStream in project apjp by jvansteirteghem.

the class HTTPSRequest method getHTTPResponseMessage.

public HTTPResponseMessage getHTTPResponseMessage() throws HTTPSRequestException {
    try {
        HTTPMessageHeader[] httpRequestMessage1Headers1 = httpRequestMessage.getHTTPMessageHeaders();
        HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1Headers1[0];
        String httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
        String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
        logger.log(2, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Value1);
        String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
        String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[1];
        String[] httpRequestMessage1Header1Values2 = httpRequestMessage1Header1Value2.split("/", -1);
        String httpRequestMessage1Header1Value3 = httpRequestMessage1Header1Values2[0];
        if (httpRequestMessage1Header1Value3.equalsIgnoreCase("https:")) {
            httpRequestMessage1Header1Value2 = "";
            for (int j = 3; j < httpRequestMessage1Header1Values2.length; j = j + 1) {
                httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Value2 + "/" + httpRequestMessage1Header1Values2[j];
            }
            httpRequestMessage1Header1Values1[1] = httpRequestMessage1Header1Value2;
        }
        httpRequestMessage1Header1Values1[2] = "HTTP/1.0";
        httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
        for (int j = 1; j < httpRequestMessage1Header1Values1.length; j = j + 1) {
            httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[j];
        }
        httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
        for (int j = 1; j < httpRequestMessage1Headers1.length; j = j + 1) {
            httpRequestMessage1Header1 = httpRequestMessage1Headers1[j];
            httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
            httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
            // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Charset")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Encoding")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Language")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Allow")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Authorization")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Connection")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Date")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expect")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expires")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("From")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Host")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Match")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Modified-Since")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-None-Match")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Range")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Unmodified-Since")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Max-Forwards")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Authorization")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Range")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Referer")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("TE")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("User-Agent")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Via")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Warning")) {
            }
            logger.log(3, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Key1 + ": " + httpRequestMessage1Header1Value1);
        }
        httpRequestMessage.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
        SecretKeySpec secretKeySpec = new SecretKeySpec(APJP.APJP_KEY.getBytes(), "ARCFOUR");
        Cipher outputCipher = Cipher.getInstance("ARCFOUR");
        outputCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
        CipherOutputStream cipherOutputStream = new CipherOutputStream(urlConnection.getOutputStream(), outputCipher);
        HTTPMessageHeader[] httpRequestMessage1Headers2 = httpRequestMessage.getHTTPMessageHeaders();
        HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1Headers2[0];
        String httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
        String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
        cipherOutputStream.write((httpRequestMessage1Header2Value1 + "\r\n").getBytes());
        for (int j = 1; j < httpRequestMessage1Headers2.length; j = j + 1) {
            httpRequestMessage1Header2 = httpRequestMessage1Headers2[j];
            httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
            httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
            cipherOutputStream.write((httpRequestMessage1Header2Key1 + ": " + httpRequestMessage1Header2Value1 + "\r\n").getBytes());
        }
        cipherOutputStream.write(("\r\n").getBytes());
        httpRequestMessage.read(cipherOutputStream);
        Cipher inputCipher = Cipher.getInstance("ARCFOUR");
        inputCipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
        CipherInputStream cipherInputStream = new CipherInputStream(urlConnection.getInputStream(), inputCipher);
        HTTPResponseMessage httpResponseMessage1 = new HTTPResponseMessage(httpRequestMessage, cipherInputStream);
        httpResponseMessage1.read();
        HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
        HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
        String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
        String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
        logger.log(2, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Value1);
        String[] httpResponseMessage1Header1Values1 = httpResponseMessage1Header1Value1.split(" ");
        httpResponseMessage1Header1Values1[0] = "HTTP/1.0";
        httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Values1[0];
        for (int j = 1; j < httpResponseMessage1Header1Values1.length; j = j + 1) {
            httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Value1 + " " + httpResponseMessage1Header1Values1[j];
        }
        httpResponseMessage1Header1.setValue(httpResponseMessage1Header1Value1);
        for (int j = 1; j < httpResponseMessage1Headers1.length; j = j + 1) {
            httpResponseMessage1Header1 = httpResponseMessage1Headers1[j];
            httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
            httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
            // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Accept-Ranges")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Age")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Allow")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Connection")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Date")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("ETag")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Expires")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Location")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Authenticate")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Retry-After")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Server")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Vary")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Via")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Warning")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("WWW-Authenticate")) {
            }
            logger.log(3, "HTTPS_REQUEST/GET_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1);
        }
        httpResponseMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
        return httpResponseMessage1;
    } catch (Exception e) {
        throw new HTTPSRequestException("HTTPS_REQUEST/GET_HTTP_RESPONSE_MESSAGE", e);
    }
}
Also used : CipherOutputStream(javax.crypto.CipherOutputStream) CipherInputStream(javax.crypto.CipherInputStream) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Cipher(javax.crypto.Cipher)

Example 90 with CipherInputStream

use of javax.crypto.CipherInputStream in project apjp by jvansteirteghem.

the class HTTPRequest method getHTTPResponseMessage.

public HTTPResponseMessage getHTTPResponseMessage() throws HTTPRequestException {
    try {
        HTTPMessageHeader[] httpRequestMessage1Headers1 = httpRequestMessage.getHTTPMessageHeaders();
        HTTPMessageHeader httpRequestMessage1Header1 = httpRequestMessage1Headers1[0];
        String httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
        String httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
        logger.log(2, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Value1);
        String[] httpRequestMessage1Header1Values1 = httpRequestMessage1Header1Value1.split(" ");
        String httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Values1[1];
        String[] httpRequestMessage1Header1Values2 = httpRequestMessage1Header1Value2.split("/", -1);
        String httpRequestMessage1Header1Value3 = httpRequestMessage1Header1Values2[0];
        if (httpRequestMessage1Header1Value3.equalsIgnoreCase("http:")) {
            httpRequestMessage1Header1Value2 = "";
            for (int j = 3; j < httpRequestMessage1Header1Values2.length; j = j + 1) {
                httpRequestMessage1Header1Value2 = httpRequestMessage1Header1Value2 + "/" + httpRequestMessage1Header1Values2[j];
            }
            httpRequestMessage1Header1Values1[1] = httpRequestMessage1Header1Value2;
        }
        httpRequestMessage1Header1Values1[2] = "HTTP/1.0";
        httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Values1[0];
        for (int j = 1; j < httpRequestMessage1Header1Values1.length; j = j + 1) {
            httpRequestMessage1Header1Value1 = httpRequestMessage1Header1Value1 + " " + httpRequestMessage1Header1Values1[j];
        }
        httpRequestMessage1Header1.setValue(httpRequestMessage1Header1Value1);
        for (int j = 1; j < httpRequestMessage1Headers1.length; j = j + 1) {
            httpRequestMessage1Header1 = httpRequestMessage1Headers1[j];
            httpRequestMessage1Header1Key1 = httpRequestMessage1Header1.getKey();
            httpRequestMessage1Header1Value1 = httpRequestMessage1Header1.getValue();
            // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Charset")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Encoding")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Accept-Language")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Allow")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Authorization")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Connection")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Date")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expect")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Expires")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("From")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Host")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Match")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Modified-Since")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-None-Match")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Range")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("If-Unmodified-Since")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Max-Forwards")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Authorization")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Range")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Referer")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("TE")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
                httpRequestMessage.removeHTTPMessageHeader(httpRequestMessage1Header1);
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
            } else // 1.0
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("User-Agent")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Via")) {
            } else // 1.1
            if (httpRequestMessage1Header1Key1.equalsIgnoreCase("Warning")) {
            }
            logger.log(3, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: REQUEST: " + httpRequestMessage1Header1Key1 + ": " + httpRequestMessage1Header1Value1);
        }
        httpRequestMessage.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
        SecretKeySpec secretKeySpec = new SecretKeySpec(APJP.APJP_KEY.getBytes(), "ARCFOUR");
        Cipher outputCipher = Cipher.getInstance("ARCFOUR");
        outputCipher.init(Cipher.ENCRYPT_MODE, secretKeySpec);
        CipherOutputStream cipherOutputStream = new CipherOutputStream(urlConnection.getOutputStream(), outputCipher);
        HTTPMessageHeader[] httpRequestMessage1Headers2 = httpRequestMessage.getHTTPMessageHeaders();
        HTTPMessageHeader httpRequestMessage1Header2 = httpRequestMessage1Headers2[0];
        String httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
        String httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
        cipherOutputStream.write((httpRequestMessage1Header2Value1 + "\r\n").getBytes());
        for (int j = 1; j < httpRequestMessage1Headers2.length; j = j + 1) {
            httpRequestMessage1Header2 = httpRequestMessage1Headers2[j];
            httpRequestMessage1Header2Key1 = httpRequestMessage1Header2.getKey();
            httpRequestMessage1Header2Value1 = httpRequestMessage1Header2.getValue();
            cipherOutputStream.write((httpRequestMessage1Header2Key1 + ": " + httpRequestMessage1Header2Value1 + "\r\n").getBytes());
        }
        cipherOutputStream.write(("\r\n").getBytes());
        httpRequestMessage.read(cipherOutputStream);
        Cipher inputCipher = Cipher.getInstance("ARCFOUR");
        inputCipher.init(Cipher.DECRYPT_MODE, secretKeySpec);
        CipherInputStream cipherInputStream = new CipherInputStream(urlConnection.getInputStream(), inputCipher);
        HTTPResponseMessage httpResponseMessage1 = new HTTPResponseMessage(httpRequestMessage, cipherInputStream);
        httpResponseMessage1.read();
        HTTPMessageHeader[] httpResponseMessage1Headers1 = httpResponseMessage1.getHTTPMessageHeaders();
        HTTPMessageHeader httpResponseMessage1Header1 = httpResponseMessage1Headers1[0];
        String httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
        String httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
        logger.log(2, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Value1);
        String[] httpResponseMessage1Header1Values1 = httpResponseMessage1Header1Value1.split(" ");
        httpResponseMessage1Header1Values1[0] = "HTTP/1.0";
        httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Values1[0];
        for (int j = 1; j < httpResponseMessage1Header1Values1.length; j = j + 1) {
            httpResponseMessage1Header1Value1 = httpResponseMessage1Header1Value1 + " " + httpResponseMessage1Header1Values1[j];
        }
        httpResponseMessage1Header1.setValue(httpResponseMessage1Header1Value1);
        for (int j = 1; j < httpResponseMessage1Headers1.length; j = j + 1) {
            httpResponseMessage1Header1 = httpResponseMessage1Headers1[j];
            httpResponseMessage1Header1Key1 = httpResponseMessage1Header1.getKey();
            httpResponseMessage1Header1Value1 = httpResponseMessage1Header1.getValue();
            // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Accept-Ranges")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Age")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Allow")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Cache-Control")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Connection")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Encoding")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Language")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Length")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Location")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-MD5")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Range")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Content-Type")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Date")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("ETag")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Expires")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Keep-Alive")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Last-Modified")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Location")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Pragma")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Authenticate")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Proxy-Connection")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Retry-After")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Server")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Trailer")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Transfer-Encoding")) {
                httpResponseMessage1.removeHTTPMessageHeader(httpResponseMessage1Header1);
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Vary")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Upgrade")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Via")) {
            } else // 1.1
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("Warning")) {
            } else // 1.0
            if (httpResponseMessage1Header1Key1.equalsIgnoreCase("WWW-Authenticate")) {
            }
            logger.log(3, "HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE: RESPONSE: " + httpResponseMessage1Header1Key1 + ": " + httpResponseMessage1Header1Value1);
        }
        httpResponseMessage1.addHTTPMessageHeader(new HTTPMessageHeader("Connection", "close"));
        return httpResponseMessage1;
    } catch (Exception e) {
        throw new HTTPRequestException("HTTP_REQUEST/GET_HTTP_RESPONSE_MESSAGE", e);
    }
}
Also used : CipherOutputStream(javax.crypto.CipherOutputStream) CipherInputStream(javax.crypto.CipherInputStream) SecretKeySpec(javax.crypto.spec.SecretKeySpec) Cipher(javax.crypto.Cipher)

Aggregations

CipherInputStream (javax.crypto.CipherInputStream)102 Cipher (javax.crypto.Cipher)66 IOException (java.io.IOException)42 InputStream (java.io.InputStream)32 ByteArrayInputStream (java.io.ByteArrayInputStream)30 IvParameterSpec (javax.crypto.spec.IvParameterSpec)21 SecretKeySpec (javax.crypto.spec.SecretKeySpec)21 FileInputStream (java.io.FileInputStream)19 InvalidKeyException (java.security.InvalidKeyException)16 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)15 InvalidAlgorithmParameterException (java.security.InvalidAlgorithmParameterException)13 NoSuchPaddingException (javax.crypto.NoSuchPaddingException)12 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 NullCipher (javax.crypto.NullCipher)11 DataInputStream (java.io.DataInputStream)9 RuntimeException (java.lang.RuntimeException)9 GeneralSecurityException (java.security.GeneralSecurityException)9 CipherOutputStream (javax.crypto.CipherOutputStream)8 BufferedInputStream (java.io.BufferedInputStream)7 Key (java.security.Key)7