This TripleDES encryption compatibility when using Java and .NET - Read Now

This TripleDES encryption compatibility when using Java and .NET - Read Now - is the keyword that you are looking for, and we have it available to you on the blog All About Gadgets, on this occasion we will discuss the article entitled This TripleDES encryption compatibility when using Java and .NET - Read Now, we as admins on this blog has been providing information to you that we collected from various sources so that the information we present a very complete and lots of start about android, latest gadgets of various brands are like samsung, sony, asus, iphone, blackberry, we also provide information about how to fix a mobile phone, flash, rooting. so do not let you stay informed about the latest gadgets in this blog, hopefully our writing easy to understand, ok let please continue reading:

he information you are looking for : This TripleDES encryption compatibility when using Java and .NET - Read Now
Full article : This TripleDES encryption compatibility when using Java and .NET - Read Now
Article .net, Article java, Article tips and tricks,

You can also see our article on:


This TripleDES encryption compatibility when using Java and .NET - Read Now

Note: This article shows you how to generate a SecretKey to use with a TripleDES encryption cipher. The shared-secret key can be 24 byte or even 16 bytes long.
For a quick brief of how TripleDES (3DES) works have a look here.

The most common problem related to encrypting something in Java and decrypting in .NET or vice-versa is a misunderstanding of the Keying options that are defined in the standards and those implemented by Java and .NET

A DES key is made up of 56 bits and 8 parity bits (8 bytes)
A 3DES key is made up of a bunch of 3, 8-byte DES keys i.e. a 24 bytes long

If you are going to use a 24 byte key for both Java and .NET, you're safe; then encryption will be compatible.

Java will force you to use only a 24 byte key when using TripleDES; the subtly is that .NET supports both a 16 byte as well as a 24 byte key.
Now If you generate a key from a MD5 hash of a shared secret, it will be just 16 bytes. .NET has no problem with this. It implements Keying Option 2. It will intelligently take the first 8 bytes and append it after the 16th byte - forming a 24 byte key. Java, *sigh* sadly doesn't do this. You'll have to spoon feed it like so:
public SecretKey getSecretKey(byte[] encryptionKey) {
 SecretKey secretKey = null;
 if (encryptionKey == null)
   return null;

byte[] keyValue = new byte[24]; // final 3DES key

if (encryptionKey.length == 16) {
 // Create the third key from the first 8 bytes
 System.arraycopy(encryptionKey, 0, keyValue, 0, 16);
 System.arraycopy(encryptionKey, 0, keyValue, 16, 8);

} else if (encryptionKey.length != 24) {
 throw new IllegalArgumentException("A TripleDES key should be 24 bytes long");

} else {
 keyValue = encryptionKey;
}
 DESedeKeySpec keySpec;
try {
 keySpec = new DESedeKeySpec(keyValue);
 SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DESede");
 secretKey = keyFactory.generateSecret(keySpec);
} catch (Exception e) {
 throw new RuntimeException("Error in key Generation",e);
}
 return secretKey;
}


Articles This TripleDES encryption compatibility when using Java and .NET - Read Now we have presented

A few information are discussed This TripleDES encryption compatibility when using Java and .NET - Read Now, hopefully we can give benefit to you in finding information on The latest technological gadgets.

You've finished reading an article This TripleDES encryption compatibility when using Java and .NET - Read Now and url link of this article is https://androiditnow.blogspot.com/2016/11/this-tripledes-encryption-compatibility.html can you use a bookmark. Hopefully this article could be useful and do not forget to look for more information in the blog All About Gadgets, thanks.

Tag : , , ,

0 Response to "This TripleDES encryption compatibility when using Java and .NET - Read Now"

Post a Comment