android studio could not find masterkey class

Viewed 980

I want to read encrypt image files in my android app https://developer.android.com/topic/security/data above link is the topic that I read and want to use it in my app in android studio but android studio could not find MasterKey class. I added the following dependency to my app module's build.gradle

dependencies {
implementation "androidx.security:security-crypto:1.0.0-rc03"

// For Identity Credential APIs
implementation "androidx.security:security-identity-credential:1.0.0-alpha01"

}

I want to test the following code in my app

    Context context = getApplicationContext();
MasterKey mainKey = new MasterKey.Builder(context)
        .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
        .build();
String fileToRead = "my_sensitive_data.txt";
EncryptedFile encryptedFile = new EncryptedFile.Builder(context,
        new File(DIRECTORY, fileToRead),
        mainKey,
        EncryptedFile.FileEncryptionScheme.AES256_GCM_HKDF_4KB
).build();

InputStream inputStream = encryptedFile.openFileInput();
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
int nextByte = inputStream.read();
while (nextByte != -1) {
    byteArrayOutputStream.write(nextByte);
    nextByte = inputStream.read();
}

byte[] plaintext = byteArrayOutputStream.toByteArray();

android studio version: 4.1

com.android.tools.build:gradle:4.0.0

compileSdkVersion 28

buildToolsVersion "29.0.2"

edit: I have this error when I sync project Failed to resolve: com.androidx.support:design:28.0.0 Show in Project Structure dialog

Affected Modules: app

Thanks to everyone who reads and helps me

0 Answers
Related