首页 > 解决方案 > 什么是android中的实体?

问题描述

我是android的初学者。我正在使用下面的代码(Facebook Conceal Library)来加密和解密视频,但我不知道实体到底是什么?我在网上搜索了很多次,也访问了developer.android.com/参考/安卓/内容/实体,但我不知道我应该为实体使用什么?

public void testEncrypt()
{
    File inputFile = new File("/storage/emulated/0/Download/video1.mp4");
    try {
        final byte[] encrypt = new byte[(int) inputFile.length()];
        ContextWrapper cw = new ContextWrapper(getApplicationContext());
        File directory = cw.getDir("/storage/emulated/0/Download/", Context.MODE_PRIVATE);
        File mypath = new File(directory, "encrypt.mp4");

        Crypto crypto = new Crypto(new SharedPrefsBackedKeyChain(this), new SystemNativeCryptoLibrary());

        if (!crypto.isAvailable()) {
            return;
        }

        OutputStream fileStream = new BufferedOutputStream(
                new FileOutputStream(mypath));
        OutputStream outputStream = crypto.getCipherOutputStream(
                fileStream, new **Entity()**);
        outputStream.write(encrypt);
        outputStream.close();
    } catch (UnsupportedOperationException e) {
        e.printStackTrace();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
    Toast.makeText(MainActivity.this,"Encrypted",Toast.LENGTH_LONG).show();
}

public Void testDecrypt() {
    Crypto crypto = new Crypto(new SharedPrefsBackedKeyChain(this),
            new SystemNativeCryptoLibrary());

    ContextWrapper cw = new ContextWrapper(getApplicationContext());
    File directory = cw.getDir("/storage/emulated/0/Download/", Context.MODE_PRIVATE);
    File file = new File(directory, "decrypt.mp4");

    try {
        FileInputStream fileStream = new FileInputStream(file);
        InputStream inputStream = crypto.getCipherInputStream(fileStream,
                new **Entity()**);

        ByteArrayOutputStream out = new ByteArrayOutputStream();

        int read;
        byte[] buffer = new byte[1024];

        while ((read = inputStream.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }

        inputStream.close();


    } catch (Exception e) {
        e.printStackTrace();
    }
    Toast.makeText(MainActivity.this, "Decrypted", Toast.LENGTH_LONG).show();
}

标签: androidencryption

解决方案


推荐阅读