- Create DES key from 56 bit binary string. Use as the secret key for DES encryption. I found the following code at the JCA docs website. Key in java using DES.
- Triple DES: DES « Security « Java. This code is from the book Java Examples in a Nutshell, 2nd Edition.,. decrypt, or generate a key.
The following are top voted examples for showing how to use javax.crypto.KeyGenerator.These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Thank you for visiting OWASP.org. We recently migrated our community to a new web platform and regretably the content for this page needed to be programmatically ported from its previous wiki page. There’s still some work to be done.
Java Cryptographic Extensions (JCE) is a set of Java API’s whichprovides cryptographic services such as encryption, secret KeyGeneration, Message Authentication code and Key Agreement. The cipherssupported by JCE include symmetric, asymmetric, block and streamciphers. JCE was an optional package to JDK v 1.2.x and 1.3.x. JCE hasbeen integrated into JDK v1.4.JCE API’s are implemented by Cryptographic Service Providers. Each ofthese cryptographic service providers implements the Service ProviderInterface which specifies the functionalities which needs to beimplemented by the service providers. Programmers can plugin any ServiceProviders for performing cryptographic functionalities provided by JCE.J2SE comes with a default provider named SunJCE.
Symmetric Encryption Algorithms provided by SunJCE
- DES - default keylength of 56 bits
- AES -
- RC2, RC4 and RC5
- IDEA
- Triple DES – default keylength 112 bits
- Blowfish – default keylength 56 bits
- PBEWithMD5AndDES
- PBEWithHmacSHA1AndDESede
- DES ede
Modes of Encryption
- ECB
- CBC
- CFB
- OFB
- PCBC
Asymmetric Encryption Algorithms implemented by SunJCE
- RSA
- Diffie-Hellman – default keylength 1024 bits
Hashing / Message Digest Algorithms implemented by SunJCE
- MD5 – default size 64 bytes
- SHA1 - default size 64 bytes
Examples
SecureRandom
SecureRandom class is used to generate a cryptographically strong pseudorandom number by using a PRNG Algorithm. The following are theadvantages of using SecureRandom over Random. 1. SecureRandom produces acryptographically strong pseudo random number generator. 2. SecureRandomproduces cryptographically strong sequences as described in RFC 1750:Randomness Recommendations forSecurity