This class provides the functionality of a secret (symmetric) key generator.
What version of Java are you using? I believe that algorithm was added with Java 6.
Henry
encryption keys are binary. They don't print well. You can store them in a file by just writing out the binary bytes, but you can't read or print the binary.
Most folks wrap the binary in a text-based encoding, usually base64 or mime.
![Key Key](/uploads/1/3/3/2/133275730/856702674.png)
The secKey is a 128-bit key, which is encoded in the BASE64Encoder. The BASE64Decoder in the following method generates an appropriate 128-bit key. AES-128 dynamic encryption and key delivery service workflow Perform the following general steps when you encrypt your assets with AES by using the Media Services key delivery service and also by using dynamic encryption: Create an asset, and upload files into the asset. Encode the asset that contains the file to the adaptive bitrate MP4 set.
Key generators are constructed using one of the
getInstance
class methods of this class. KeyGenerator objects are reusable, i.e., after a key has been generated, the same KeyGenerator object can be re-used to generate further keys.
With thousands of available add-ons, AutoCAD software provides the ultimate in flexibility, customized for your specific needs. Speed documentation, share ideas seamlessly, and explore ideas more intuitively in 3D. It will allow you to design and shape the world around you using its powerful and flexible features. Hi Author, i had installed several Version of AutoCAD but the crack wont work when i patch it “Always said apply patch when license screen appear” but my license screens had appear and i try to close and re-try, restart but still cant be patched. I had done the run as administrator when open up the crack and close all the internet, windows firewall. https://conceptsclever852.weebly.com/blog/autocad-2014-product-key-generator-download.
There are two ways to generate a key: in an algorithm-independent manner, and in an algorithm-specific manner. The only difference between the two is the initialization of the object:
- Algorithm-Independent InitializationAll key generators share the concepts of a keysize and a source of randomness. There is an
init
method in this KeyGenerator class that takes these two universally shared types of arguments. There is also one that takes just akeysize
argument, and uses the SecureRandom implementation of the highest-priority installed provider as the source of randomness (or a system-provided source of randomness if none of the installed providers supply a SecureRandom implementation), and one that takes just a source of randomness.Windows xp pro sp3 key generator. Since no other parameters are specified when you call the above algorithm-independentinit
methods, it is up to the provider what to do about the algorithm-specific parameters (if any) to be associated with each of the keys. - Algorithm-Specific InitializationFor situations where a set of algorithm-specific parameters already exists, there are two
init
methods that have anAlgorithmParameterSpec
argument. One also has aSecureRandom
argument, while the other uses the SecureRandom implementation of the highest-priority installed provider as the source of randomness (or a system-provided source of randomness if none of the installed providers supply a SecureRandom implementation).
In case the client does not explicitly initialize the KeyGenerator (via a call to an
init
method), each provider must supply (and document) a default initialization. Every implementation of the Java platform is required to support the following standard
KeyGenerator
algorithms with the keysizes in parentheses: - AES (128)
- DES (56)
- DESede (168)
- HmacSHA1
- HmacSHA256
Greenhorn
posted 11 years ago- 1
I have written a below program to encrypt a file with AES 128 algorithm. This code works fine. It does encrypt and decrypt file successfully.
Here in this code I am generating SecretKey in the main() method with the use of key generator. But can anybody please tell me how can I generate SecretKey based on user's password in the below program?
Thanks in Advance,
Jenish
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import java.security.spec.AlgorithmParameterSpec;
public class AESEncrypter
{
Cipher ecipher;
Cipher dcipher;
public AESEncrypter(SecretKey key)
{
// Create an 8-byte initialization vector
byte[] iv = new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
try
{
ecipher = Cipher.getInstance('AES/CBC/PKCS5Padding');
dcipher = Cipher.getInstance('AES/CBC/PKCS5Padding');
// CBC requires an initialization vector
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Buffer used to transport the bytes from one stream to another
byte[] buf = new byte[1024];
public void encrypt(InputStream in, OutputStream out)
{
try
{
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e)
{
}
}
public void decrypt(InputStream in, OutputStream out)
{
try
{
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e)
{
}
}
public static void main(String args[])
{
try
{
// Generate a temporary key. In practice, you would save this key.
// See also e464 Encrypting with DES Using a Pass Phrase.
KeyGenerator kgen = KeyGenerator.getInstance('AES');
kgen.init(128);
SecretKey key = kgen.generateKey();
// Create encrypter/decrypter class
AESEncrypter encrypter = new AESEncrypter(key);
// Encrypt
encrypter.encrypt(new FileInputStream('E:keeper.txt'),new FileOutputStream('E:Encrypted.txt'));
// Decrypt
encrypter.decrypt(new FileInputStream('E:keeper.txt'),new FileOutputStream('E:Decrypted.txt'));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Here in this code I am generating SecretKey in the main() method with the use of key generator. But can anybody please tell me how can I generate SecretKey based on user's password in the below program?
Thanks in Advance,
Jenish
import java.io.InputStream;
import java.io.OutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.KeyGenerator;
import java.security.spec.AlgorithmParameterSpec;
public class AESEncrypter
{
Cipher ecipher;
Cipher dcipher;
public AESEncrypter(SecretKey key)
{
// Create an 8-byte initialization vector
byte[] iv = new byte[]
{
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
};
AlgorithmParameterSpec paramSpec = new IvParameterSpec(iv);
try
{
ecipher = Cipher.getInstance('AES/CBC/PKCS5Padding');
dcipher = Cipher.getInstance('AES/CBC/PKCS5Padding');
// CBC requires an initialization vector
ecipher.init(Cipher.ENCRYPT_MODE, key, paramSpec);
dcipher.init(Cipher.DECRYPT_MODE, key, paramSpec);
}
catch (Exception e)
{
e.printStackTrace();
}
}
// Buffer used to transport the bytes from one stream to another
byte[] buf = new byte[1024];
public void encrypt(InputStream in, OutputStream out)
{
try
{
// Bytes written to out will be encrypted
out = new CipherOutputStream(out, ecipher);
// Read in the cleartext bytes and write to out to encrypt
int numRead = 0;
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e)
{
}
}
public void decrypt(InputStream in, OutputStream out)
{
try
{
// Bytes read from in will be decrypted
in = new CipherInputStream(in, dcipher);
// Read in the decrypted bytes and write the cleartext to out
int numRead = 0;
while ((numRead = in.read(buf)) >= 0)
{
out.write(buf, 0, numRead);
}
out.close();
}
catch (java.io.IOException e)
{
}
}
public static void main(String args[])
{
try
{
// Generate a temporary key. In practice, you would save this key.
// See also e464 Encrypting with DES Using a Pass Phrase.
KeyGenerator kgen = KeyGenerator.getInstance('AES');
kgen.init(128);
SecretKey key = kgen.generateKey();
// Create encrypter/decrypter class
AESEncrypter encrypter = new AESEncrypter(key);
// Encrypt
encrypter.encrypt(new FileInputStream('E:keeper.txt'),new FileOutputStream('E:Encrypted.txt'));
// Decrypt
encrypter.decrypt(new FileInputStream('E:keeper.txt'),new FileOutputStream('E:Decrypted.txt'));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
Ranch Hand
posted 11 years agoYou can use the PBKDF2 algorithm to generate a key from a password; see this answer from a while ago.
Please make sure you use a different, random Initialisation Vector for each password-based key and each message, and save it with the encrypted data. Otherwise each message using the same key and starting with the same data will be encrypted the same, giving attackers a head start.
Please make sure you use a different, random Initialisation Vector for each password-based key and each message, and save it with the encrypted data. Otherwise each message using the same key and starting with the same data will be encrypted the same, giving attackers a head start.
Greenhorn
posted 11 years agoHi,
Thanks for your reply.
I have tried copy pasting the code from the thread you mentioned but I got the exception on line
SecretKeyFactory factory = SecretKeyFactory.getInstance('PBKDF2WithHmacSHA1');
java.security.NoSuchAlgorithmException: Algorithm PBKDF2WithHmacSHA1 not available
at javax.crypto.SunJCE_b.a(DashoA12275)
at javax.crypto.SecretKeyFactory.getInstance(DashoA12275)
at ftpserver.AESEncrypter.main(AESEncrypter.java:107)
Can you please tell me what is wrong with my code?
Thanks in Advance,
Jenish
Thanks for your reply.
I have tried copy pasting the code from the thread you mentioned but I got the exception on line
SecretKeyFactory factory = SecretKeyFactory.getInstance('PBKDF2WithHmacSHA1');
java.security.NoSuchAlgorithmException: Algorithm PBKDF2WithHmacSHA1 not available
at javax.crypto.SunJCE_b.a(DashoA12275)
at javax.crypto.SecretKeyFactory.getInstance(DashoA12275)
at ftpserver.AESEncrypter.main(AESEncrypter.java:107)
Can you please tell me what is wrong with my code?
Thanks in Advance,
Jenish
author
posted 11 years agoCan you please tell me what is wrong with my code?
What version of Java are you using? I believe that algorithm was added with Java 6.
Henry
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Greenhorn
posted 11 years agoCarey's code snippet from the other thread works just fine for me using the Sun JDK 1.5 and Sun's own built-in JCE provider.
Ranch Hand
posted 11 years agoThat's the stack trace I get from J2RE 1.4.2. Even if for some reason you can't move to a supported version of Java, it's still a good algorithm, and you should be able to find a compatible version somewhere.
Greenhorn
posted 11 years agoHey it worked fine I just changed my JRE version.
Thanks a lot for this wonderful program Carey.
Thanks a lot for this wonderful program Carey.
Greenhorn
posted 9 years agoHi, I'm new to encryption. Was wondering how can I store the key or print out the value of the key? Thanks!
Rancher
posted 9 years agolily ch wrote:Hi, I'm new to encryption. Was wondering how can I store the key or print out the value of the key? Thanks!
encryption keys are binary. They don't print well. You can store them in a file by just writing out the binary bytes, but you can't read or print the binary.
Most folks wrap the binary in a text-based encoding, usually base64 or mime.
Greenhorn
posted 7 years ago![Key Key](/uploads/1/3/3/2/133275730/856702674.png)
Java Aes 128 Key Generator Reviews
Encryption using AES with key password
https://coderanch.com/t/581824/java/java/Decrypt-AES-password
https://coderanch.com/t/581824/java/java/Decrypt-AES-password