Java Code Examples for org.telegram.messenger.Utilities#aesCtrDecryptionByteArray()

The following examples show how to use org.telegram.messenger.Utilities#aesCtrDecryptionByteArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncryptedFileInputStream.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] b, int off, int len) throws IOException {
    if (currentMode == MODE_CBC && fileOffset == 0) {
        byte[] temp = new byte[32];
        super.read(temp, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
        fileOffset += 32;
        skip((temp[0] & 0xff) - 32);
    }
    int result = super.read(b, off, len);
    if (currentMode == MODE_CBC) {
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
    } else if (currentMode == MODE_CTR) {
        Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset);
    }
    fileOffset += len;
    return result;
}
 
Example 2
Source File: EncryptedFileDataSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException {
    if (readLength == 0) {
        return 0;
    } else if (bytesRemaining == 0) {
        return C.RESULT_END_OF_INPUT;
    } else {
        int bytesRead;
        try {
            bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength));
            Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset);
            fileOffset += bytesRead;
        } catch (IOException e) {
            throw new EncryptedFileDataSourceException(e);
        }

        if (bytesRead > 0) {
            bytesRemaining -= bytesRead;
            if (listener != null) {
                listener.onBytesTransferred(this, dataSpec, false, bytesRead);
            }
        }

        return bytesRead;
    }
}
 
Example 3
Source File: EncryptedFileInputStream.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] b, int off, int len) throws IOException {
    if (currentMode == MODE_CBC && fileOffset == 0) {
        byte[] temp = new byte[32];
        super.read(temp, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
        fileOffset += 32;
        skip((temp[0] & 0xff) - 32);
    }
    int result = super.read(b, off, len);
    if (currentMode == MODE_CBC) {
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
    } else if (currentMode == MODE_CTR) {
        Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset);
    }
    fileOffset += len;
    return result;
}
 
Example 4
Source File: EncryptedFileDataSource.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException {
    if (readLength == 0) {
        return 0;
    } else if (bytesRemaining == 0) {
        return C.RESULT_END_OF_INPUT;
    } else {
        int bytesRead;
        try {
            bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength));
            Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset);
            fileOffset += bytesRead;
        } catch (IOException e) {
            throw new EncryptedFileDataSourceException(e);
        }

        if (bytesRead > 0) {
            bytesRemaining -= bytesRead;
            if (listener != null) {
                listener.onBytesTransferred(this, dataSpec, false, bytesRead);
            }
        }

        return bytesRead;
    }
}
 
Example 5
Source File: EncryptedFileInputStream.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] b, int off, int len) throws IOException {
    if (currentMode == MODE_CBC && fileOffset == 0) {
        byte[] temp = new byte[32];
        super.read(temp, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
        fileOffset += 32;
        skip((temp[0] & 0xff) - 32);
    }
    int result = super.read(b, off, len);
    if (currentMode == MODE_CBC) {
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
    } else if (currentMode == MODE_CTR) {
        Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset);
    }
    fileOffset += len;
    return result;
}
 
Example 6
Source File: EncryptedFileDataSource.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException {
    if (readLength == 0) {
        return 0;
    } else if (bytesRemaining == 0) {
        return C.RESULT_END_OF_INPUT;
    } else {
        int bytesRead;
        try {
            bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength));
            Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset);
            fileOffset += bytesRead;
        } catch (IOException e) {
            throw new EncryptedFileDataSourceException(e);
        }

        if (bytesRead > 0) {
            bytesRemaining -= bytesRead;
            bytesTransferred(bytesRead);
        }

        return bytesRead;
    }
}
 
Example 7
Source File: EncryptedFileInputStream.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] b, int off, int len) throws IOException {
    if (currentMode == MODE_CBC && fileOffset == 0) {
        byte[] temp = new byte[32];
        super.read(temp, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
        fileOffset += 32;
        skip((temp[0] & 0xff) - 32);
    }
    int result = super.read(b, off, len);
    if (currentMode == MODE_CBC) {
        Utilities.aesCbcEncryptionByteArraySafe(b, key, iv, off, len, fileOffset, 0);
    } else if (currentMode == MODE_CTR) {
        Utilities.aesCtrDecryptionByteArray(b, key, iv, off, len, fileOffset);
    }
    fileOffset += len;
    return result;
}
 
Example 8
Source File: EncryptedFileDataSource.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
@Override
public int read(byte[] buffer, int offset, int readLength) throws EncryptedFileDataSourceException {
    if (readLength == 0) {
        return 0;
    } else if (bytesRemaining == 0) {
        return C.RESULT_END_OF_INPUT;
    } else {
        int bytesRead;
        try {
            bytesRead = file.read(buffer, offset, (int) Math.min(bytesRemaining, readLength));
            Utilities.aesCtrDecryptionByteArray(buffer, key, iv, offset, bytesRead, fileOffset);
            fileOffset += bytesRead;
        } catch (IOException e) {
            throw new EncryptedFileDataSourceException(e);
        }

        if (bytesRead > 0) {
            bytesRemaining -= bytesRead;
            bytesTransferred(bytesRead);
        }

        return bytesRead;
    }
}
 
Example 9
Source File: EncryptedFileInputStream.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void decryptBytesWithKeyFile(byte[] bytes, int offset, int length, File keyFile) throws Exception {
    byte[] key = new byte[32];
    byte[] iv = new byte[16];
    RandomAccessFile randomAccessFile = new RandomAccessFile(keyFile, "r");
    randomAccessFile.read(key, 0, 32);
    randomAccessFile.read(iv, 0, 16);
    randomAccessFile.close();
    Utilities.aesCtrDecryptionByteArray(bytes, key, iv, offset, length, 0);
}
 
Example 10
Source File: EncryptedFileInputStream.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
public static void decryptBytesWithKeyFile(byte[] bytes, int offset, int length, File keyFile) throws Exception {
    byte[] key = new byte[32];
    byte[] iv = new byte[16];
    RandomAccessFile randomAccessFile = new RandomAccessFile(keyFile, "r");
    randomAccessFile.read(key, 0, 32);
    randomAccessFile.read(iv, 0, 16);
    randomAccessFile.close();
    Utilities.aesCtrDecryptionByteArray(bytes, key, iv, offset, length, 0);
}
 
Example 11
Source File: EncryptedFileInputStream.java    From Telegram-FOSS with GNU General Public License v2.0 5 votes vote down vote up
public static void decryptBytesWithKeyFile(byte[] bytes, int offset, int length, File keyFile) throws Exception {
    byte[] key = new byte[32];
    byte[] iv = new byte[16];
    RandomAccessFile randomAccessFile = new RandomAccessFile(keyFile, "r");
    randomAccessFile.read(key, 0, 32);
    randomAccessFile.read(iv, 0, 16);
    randomAccessFile.close();
    Utilities.aesCtrDecryptionByteArray(bytes, key, iv, offset, length, 0);
}
 
Example 12
Source File: EncryptedFileInputStream.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void decryptBytesWithKeyFile(byte[] bytes, int offset, int length, File keyFile) throws Exception {
    byte[] key = new byte[32];
    byte[] iv = new byte[16];
    RandomAccessFile randomAccessFile = new RandomAccessFile(keyFile, "r");
    randomAccessFile.read(key, 0, 32);
    randomAccessFile.read(iv, 0, 16);
    randomAccessFile.close();
    Utilities.aesCtrDecryptionByteArray(bytes, key, iv, offset, length, 0);
}