If you think the Android project encrypted-camera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright (C) 2014 Andrew Reitz/*fromwww.java2s.com*/
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.andrewreitz.encryptedcamera.di.module;
import android.content.Context;
import com.andrewreitz.encryptedcamera.EncryptedCameraApp;
import com.andrewreitz.encryptedcamera.di.annotation.ForApplication;
import com.andrewreitz.encryptedcamera.encryption.EncryptionProvider;
import com.andrewreitz.encryptedcamera.encryption.EncryptionProviderImpl;
import com.andrewreitz.encryptedcamera.encryption.KeyManager;
import com.andrewreitz.encryptedcamera.encryption.KeyManagerImpl;
import com.andrewreitz.encryptedcamera.sharedpreference.AppPreferenceManager;
import com.andrewreitz.encryptedcamera.sharedpreference.SharedPreferenceService;
import java.io.IOException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableKeyException;
import java.security.cert.CertificateException;
import javax.crypto.Cipher;
import javax.crypto.NoSuchPaddingException;
import javax.inject.Singleton;
import dagger.Module;
import dagger.Provides;
import timber.log.Timber;
@Module(
complete = false,
library = true
)
@SuppressWarnings("UnusedDeclaration")
publicclass EncryptionModule {
@Provides
@Singleton KeyManager provideKeyManager(@ForApplication Context context) {
try {
returnnew KeyManagerImpl(context);
} catch (KeyStoreException | IOException | CertificateException | NoSuchAlgorithmException e) {
thrownew RuntimeException(e);
}
}
@Provides Cipher provideCipher() {
try {
return Cipher.getInstance(EncryptedCameraApp.CIPHER_TRANSFORMATION);
} catch (NoSuchAlgorithmException | NoSuchPaddingException e) {
thrownew RuntimeException(e);
}
}
@Provides
@Singleton
EncryptionProvider provideEncryptionProvider(Cipher cipher, KeyManager keyManager, AppPreferenceManager preferenceManager) {
try {
returnnew EncryptionProviderImpl(
cipher,
keyManager.getKey(EncryptedCameraApp.KEY_STORE_ALIAS),
preferenceManager.getIv()
);
} catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
Timber.w(e, "Could not create EncryptionProvider");
thrownew RuntimeException(e);
}
}
}