Encrypt mails - No Provider configured for S/MIME - android

From this codesnippet:
try {
EncryptionUtils smimeUtils = EncryptionManager.getEncryptionUtils(EncryptionManager.SMIME);
char[] smimePw = new String("hello world").toCharArray();
EncryptionKeyManager smimeKeyMgr = smimeUtils.createKeyManager();
smimeKeyMgr.loadPrivateKeystore(privateKeyStore, smimePw);
} catch (NoSuchProviderException e) {
Log.e("NoSuchProvider: ", e.getMessage());
} catch (CertificateException e) {
Log.e("Certificate: ", e.getMessage());
} catch (KeyStoreException e) {
Log.e("KeyStore: ", e.getMessage());
} catch (NoSuchAlgorithmException e) {
Log.e("No Such Algorithm: ", e.getMessage());
} catch (IOException e) {
Log.e("IO: ", e.getMessage());
}
I try to load the S/MIME encryption manager, but this code throws an NoSuchProviderException telling me this:
No provider configured for S/MIME
I'm following this guide, which is telling me to add the following .jar-files:
javamail-crypto.jar
bcprov-jdk14-122.jar
bcmail-jdk14-122.jar
I couldn't find the extact version with the ending -122 but I included the following jar-files to my build path:
bcprov-jdk14-147
bcmail-jdk14-147
javamail-crypto
javamail-crypto-bouncycastle-smime
But it still throws the exception, could anybody give me a hint on how to solve this issue?

Related

Cipher functions:OPENSSL_internal:BAD_DECRYPT in android Oreo

Android Oreo version 8 throws bad decrypt error in production. For other android versions code is working fine.
Algorithm used is "AES/CBC/PKCS5Padding".
public String decrypt(String _encryptedText, String _key, String _iv)
throws InvalidKeyException, UnsupportedEncodingException,
InvalidAlgorithmParameterException, IllegalBlockSizeException,
BadPaddingException {
//Log.d("enetered decryption", "enetered decryption");
return encryptDecrypt(_encryptedText, _key, EncryptMode.DECRYPT, _iv);
}
public String decryptionflag(String input, String iv) {
String output = "";
try {
// CryptLib _crypt = new CryptLib();
String plainText = input;
CryptLib _crypt = new CryptLib();
output = _crypt.decrypt(plainText, key, iv); // decrypt
//Log.d("decrypted flag is", "" + output);
} catch (InvalidAlgorithmParameterException e) {
// TODO Auto-generated catch block
Log.e("", "Exception" + e.getMessage());
} catch (InvalidKeyException e){
Log.e("", "Exception" + e.getMessage());
} catch (UnsupportedEncodingException e){
Log.e("", "Exception" + e.getMessage());
} catch (BadPaddingException e){
Log.e("", "Exception" + e.getMessage());
} catch (IllegalBlockSizeException e){
Log.e("", "Exception" + e.getMessage());
} catch (NoSuchAlgorithmException e){
Log.e("", "Exception" + e.getMessage());
} catch (NoSuchPaddingException e){
Log.e("", "Exception" + e.getMessage());
}
return output;
}
Keys used for encryption and decryption are same. And this code is working for UAT (android oreo version) but giving error for production.

XMPP error reply received from myroom#conference.****/myroom#conference.****: XMPPError: item-not-found - cancel

I am not able to join the room. I have gone through the documentation XMPP Instant Room Error
Here is how i am creating instant room:
try {
UserSearchManager usm = new UserSearchManager(Utils.connection);
List<DomainBareJid> services = usm.getSearchServices();
String roomjid = "myroom#" + services.get(0);
mucJid = JidCreate.entityBareFrom(roomjid);
Log.d(TAG, mucJid.toString());
// Create the nickname.
nickname = Resourcepart.from(roomjid);
Log.d(TAG, nickname.toString());
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
}
// Get the MultiUserChatManager
manager = MultiUserChatManager.getInstanceFor(Utils.connection);
// Get a MultiUserChat using MultiUserChatManager
MultiUserChat muc = manager.getMultiUserChat(mucJid);
// Create the room and send an empty configuration form to make this an instant room
try {
// Prepare a list of owners of the new room
Set<Jid> owners = JidUtil.jidSetFrom(new String[] { "54321#rahul", "12345#rahul" });
muc.create(nickname)
.getConfigFormManager()
.setRoomOwners(owners)
.submitConfigurationForm();
muc.sendConfigurationForm(new Form(DataForm.Type.submit));
muc.join(nickname);
EntityBareJid invitemucJid = JidCreate.entityBareFrom("12345#rahul");
muc.invite(invitemucJid, "testing");
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucAlreadyJoinedException e) {
e.printStackTrace();
} catch (MultiUserChatException.MissingMucCreationAcknowledgeException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (MultiUserChatException.MucConfigurationNotSupportedException e) {
e.printStackTrace();
}
The MUC room is getting created successfully. But when i am checking through Invitation Listener and trying to join the room. It is giving error.
The Invitation listener code is as follow:
try {
Resourcepart nickname = Resourcepart.from(room.getRoom().toString());
room.join(nickname);
Log.d(TAG, "room status---> " + room.isJoined());
runOnUiThread(new Runnable() {
#Override
public void run() {
if (room.isJoined()) {
Toast.makeText(FriendListActivity.this, "Joined", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(FriendListActivity.this, "Not joined", Toast.LENGTH_SHORT).show();
}
}
});
} catch (XmppStringprepException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (MultiUserChatException.NotAMucServiceException e) {
e.printStackTrace();
}
Below is screen shot of the stack Trace
As per the documentation it says that the MUC room is locked. But I have created instant room along with default configuration.
Maybe it's a network error, I do somethings wrong if I use Wifi but get corrcet result with cellular network.

Unable to set path in jaudiotagger

I'm trying to edit tags of audio files and for that I'm using JaudioTagger. But a problem exists and I can't figure it out.
I'm getting this error:
java.lang.NoSuchMethodError: No virtual method toPath()Ljava/nio/file/Path; in class Ljava/io/File; or its super classes (declaration of 'java.io.File' appears in /system/framework/core-oj.jar)
And my code for getting tags of audio files :
File path = new File(songInfoModel.getData());
Log.e("Path: ", path.toString());
try {
AudioFile f = AudioFileIO.read(path);
Tag tag = f.getTag();
String artist = tag.getFirst(FieldKey.ARTIST);
tag.getFirst(FieldKey.ALBUM);
tag.getFirst(FieldKey.TITLE);
tag.getFirst(FieldKey.COMMENT);
tag.getFirst(FieldKey.YEAR);
tag.getFirst(FieldKey.TRACK);
tag.getFirst(FieldKey.DISC_NO);
tag.getFirst(FieldKey.COMPOSER);
tag.getFirst(FieldKey.ARTIST_SORT);
Log.e("Artist: ",artist);
} catch (CannotReadException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (TagException e) {
e.printStackTrace();
} catch (ReadOnlyFileException e) {
e.printStackTrace();
} catch (InvalidAudioFrameException e) {
e.printStackTrace();
}

How to fix Not implemented error..(this code will be throw the error)

It's my code:
try {
System.out.println("Cloudinaryyyy 0000 :");
Map result = cloudinary.api().resources(ObjectUtils.asMap("resource_type","raw"));
System.out.println("Cloudinaryyyy :"+result);
}
catch (IOException e) {
Log.d("DownloadManager", "Error:" + e);
}
catch (NetworkOnMainThreadException e) {
System.out.println("Error 3" + e);
} catch (Exception e) {
e.printStackTrace();
System.out.println("Error 3" + e);
}
In the cloudinary it throws the exception.
Did you remember to configure the Cloudinary object?
Map config = new HashMap();
config.put("cloud_name", "n07t21i7");
config.put("api_key", "123456789012345");
config.put("api_secret", "abcdeghijklmnopqrstuvwxyz12");
Cloudinary cloudinary = new Cloudinary(config);
Also, you can try to run the sample projects on https://github.com/cloudinary/cloudinary_java

RSA encryption/decryption crashes on android 2.2 [duplicate]

This question already has an answer here:
Problems outsourcing RSA encryption and decryption
(1 answer)
Closed 9 years ago.
i'm developing an android app. Unfortunately i have a compatibility problem. My source code works with firmware 4.1, but crashes with devices with firmware 2.2. The error seems to be a "ClassNotFoundException" caused by the ObjectInputStream.
My sourcecode for the encryption and decryption:
private Key getPublicKey() {
try {
InputStream fis = activity.getResources().openRawResource(R.raw.publick);
ObjectInputStream ois = new ObjectInputStream(fis);
Key RSApublicKey = (Key) ois.readObject();
return RSApublicKey;
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
private Key getPrivateKey() {
try {
InputStream fis = activity.getResources().openRawResource(R.raw.privatek);
ObjectInputStream ois = new ObjectInputStream(fis);
Key RSAprivateKey = (Key) ois.readObject();
return RSAprivateKey;
}
catch (FileNotFoundException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
catch (ClassNotFoundException e) {
Log.e("error", "Error: " + e);
e.printStackTrace();
}
return null;
}
public byte[] encrypt(String data) {
byte[] encrypted = null;
try {
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, getPublicKey());
encrypted = cipher.doFinal(data.getBytes());
}
catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
catch (BadPaddingException e) {
e.printStackTrace();
}
catch (InvalidKeyException e) {
e.printStackTrace();
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
catch (NoSuchProviderException e) {
e.printStackTrace();
}
return encrypted;
}
public String decrypt(byte[] encrypted) {
byte[] decrypted = null;
try {
Cipher cipher;
cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.DECRYPT_MODE, getPrivateKey());
decrypted = cipher.doFinal(encrypted);
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (NoSuchPaddingException e) {
e.printStackTrace();
}
catch (InvalidKeyException e) {
e.printStackTrace();
}
catch (IllegalBlockSizeException e) {
e.printStackTrace();
}
catch (BadPaddingException e) {
e.printStackTrace();
}
catch (NoSuchProviderException e) {
e.printStackTrace();
}
return new String(decrypted);
}
The error in logcat:
03-23 10:13:19.706: E/Error(427): Error: java.lang.ClassNotFoundException: com.android.org.bouncycastle.jce.provider.JCERSAPrivateCrtKey
Do you have any ideas, how i could get it work with android 2.2?
You are better off using the Key.getEncoded() method to serialize the key. The Key.getFormat() already hints that RSA private keys should default to PKCS#8 encoding.
You can then use the PKCS8EncodedKeySpec class and an instance of an "RSA" KeyFactory to deserialize the resulting byte array.
The serialized keys may not work correctly over different implementations of PrivateKey (as you've already found out by now), and PKCS#8 is a well defined and often used standard.
Well, if it works on 4.1+ but not on 2.2, I guess it's a class from android that has been included after 2.2. You can test this by trying to compile with android 2.2 a project that uses this class and see if you can. If this is the case just find it and include it in your project.

Categories

Resources