Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于android的Facebook隐藏加密始终不可用_Android_Encryption - Fatal编程技术网

用于android的Facebook隐藏加密始终不可用

用于android的Facebook隐藏加密始终不可用,android,encryption,Android,Encryption,我无法在android应用程序中使用库。crypto似乎总是在crypto.isAvailable()上返回true。 另外,我使用的是Android 1.0.2,它没有明确列出包含的库,但我已将它放在正确的libs文件夹中 我在前面的链接中包含了Jar和本机二进制文件。.zip文件作为以下文件包含在生成中: compile fileTree(dir: 'libs', include: ['*.jar', '*.zip']) 这个构建似乎有效。我验证了本机库:cryptox.so和隐藏.so包

我无法在android应用程序中使用库。
crypto
似乎总是在
crypto.isAvailable()上返回true。
另外,我使用的是Android 1.0.2,它没有明确列出包含的库,但我已将它放在正确的libs文件夹中

我在前面的链接中包含了Jar和本机二进制文件。.zip文件作为以下文件包含在生成中:

compile fileTree(dir: 'libs', include: ['*.jar', '*.zip'])
这个构建似乎有效。我验证了本机库:
cryptox.so
隐藏.so
包含在apk/libs中,而另一个jar二进制文件包,如
com.facebook.crypto
包含在
classes.dex

以下是活动代码:

import com.facebook.crypto.Crypto;
import com.facebook.crypto.Entity;
import com.facebook.crypto.keychain.SharedPrefsBackedKeyChain;
import com.facebook.crypto.util.SystemNativeCryptoLibrary;

public class ConcealActivity extends Activity implements View.OnClickListener {
public static String filename = "data.txt";
public static String filepath = "concealedata";
public static String TAG = "com.zing.ConcealActivity";
File myInternalFile;
Crypto crypto;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_conceal);

    Log.i(TAG, "created method.");
    ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
    File directory = contextWrapper.getDir(filepath, Context.MODE_PRIVATE);
    myInternalFile = new File(directory, filename);
    crypto = new Crypto(new SharedPrefsBackedKeyChain(this), new SystemNativeCryptoLibrary());
    Button cencrypt = (Button) findViewById(R.id.cencrypt);
    cencrypt.setOnClickListener(this);

    Button cdecrypt = (Button) findViewById(R.id.cdecrypt);
    cdecrypt.setOnClickListener(this);
}

@Override
public void onClick(View v) {
    Log.i(TAG, "onclick method.");
    EditText myInputText = (EditText) findViewById(R.id.inputText);
    TextView responseText = (TextView) findViewById(R.id.responseText);
    String myData = "";

    switch (v.getId()) {
        case R.id.cencrypt:
            encryptandsave(myInputText.getText().toString().getBytes());
            myInputText.setText("");
            responseText.setText(readFile(myInternalFile));
            break;

        case R.id.cdecrypt:
            responseText.setText(readanddecrypt());
            break;
    }
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.menu_conceal, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();

    //noinspection SimplifiableIfStatement
    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
//始终满足以下第一个条件意味着库未正确加载

// Encrypts the data and saves to directory
public void encryptandsave(byte[] plainTextBytes) {
    try {
    // Check for whether the crypto functionality is available
    // This might fail if android does not load libaries correctly.
        if (!crypto.isAvailable()) {
            Log.e(TAG, "Cipher unavailable.");
            return;
        }

        OutputStream fileStream = new BufferedOutputStream(new FileOutputStream(myInternalFile));
        OutputStream outputStream = crypto.getCipherOutputStream(fileStream, new Entity("Password"));
        outputStream.write(plainTextBytes);
        outputStream.close();
    } catch (Exception e) {
        Log.e(TAG, "EXCEPTION encryptandsave: " + e.getMessage());
    }
}

// decode encrypted file and returns Bitmap
private String readanddecrypt() {
    try {
        if (!crypto.isAvailable()) {
            Log.e(TAG, "Cipher unavailable.");
            return "";
        }
        FileInputStream fileStream = new FileInputStream(filename);
        InputStream inputStream = crypto.getCipherInputStream(fileStream, new Entity("Password"));
        ByteArrayOutputStream out = new ByteArrayOutputStream();

        int read;
        byte[] buffer = new byte[1024];
        while ((read = inputStream.read(buffer)) != -1) {
            out.write(buffer, 0, read);
        }
        inputStream.close();
        return out.toString();
    } catch (Exception e) {
        Log.e(TAG, "EXCEPTION readanddecrypt: " + e.getMessage());
    }
    return null;
}

public String readFile(File internalFile) {
    StringBuilder sb = new StringBuilder();
    try {
        FileInputStream fis = new FileInputStream(internalFile);
        DataInputStream in = new DataInputStream(fis);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        while ((strLine = br.readLine()) != null) {
            sb.append(strLine);
        }
        in.close();
    } catch (IOException e) {
        Log.e(TAG, "EXCEPTION readFile: " + e.getMessage());
        return "";
    }
    return sb.toString();
}
}

我不确定库或代码是否有问题

在jar内部,代码似乎失败了

com.facebook.crypto.util.SystemNativeCryptoLibrary.java

private static final ArrayList<String> LIBS = new ArrayList<String>() {{
  add("cryptox");
  add("conceal");
}};
就是那个有效的。
以下是图书馆需要使用的结构。
项目:
|--lib:
|--|--armeabi:
|--|--|--.so文件


请注意,下载的
libs.zip
将所有库文件压缩到
libs
根文件夹中,需要将其更改为
lib
,以便将库正确绑定到
.apk

中,您可以尝试将.so文件相应地放在/app/src/main/jniLibs/中

app
+-src
  +-main
    +-jniLibs
      +-armeabi
      | +-libconceal.so
      +-armeabi-v7a
      | +-libconceal.so
      +-mips
      +-x86
        +-libconceal.so
app
+-src
  +-main
    +-jniLibs
      +-armeabi
      | +-libconceal.so
      +-armeabi-v7a
      | +-libconceal.so
      +-mips
      +-x86
        +-libconceal.so