Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Security
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Security
Sorry about spamming the board with questions! But here another question about PBE encryption
Rob Lee
Greenhorn
Posts: 12
posted 11 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hello all,
public class passphrase { static String algorithm = "AES"; public static String ss = "the queen diamond jubilee"; static char[] S=ss.toCharArray(); static String secretData = "Very Secret Data!!"; private static SealedObject myEncryptedMessage; static byte[] salt = "a9v5n38s".getBytes(); public passphrase() throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, IOException, ClassNotFoundException, DecoderException{ encrypt(secretData); decrypt(encrypt(secretData)); } public static byte[] gensalt() throws DecoderException{ byte[] x=Hex.decodeHex("ab987e8999ee".toCharArray()); return x; } public static byte[] convert(String h) { char[] buffer = ss.toCharArray(); byte[] b = new byte[buffer.length]; for (int i = 0; i < b.length; i++) { b[i] = (byte) buffer[i]; } return b; } public static String encrypt (String lp) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, UnsupportedEncodingException, IllegalBlockSizeException, BadPaddingException, IOException, DecoderException{ PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 10); PBEKeySpec pbeKeySpec = new PBEKeySpec(S); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); SecretKey key = factory.generateSecret(pbeKeySpec); Cipher c = Cipher.getInstance("PBEWithMD5AndDES"); c.init(Cipher.ENCRYPT_MODE,key,pbeParamSpec); byte[] input = secretData.getBytes("UTF-8"); byte[] encrypted = c.doFinal(input); String encryptedString = new String(Base64.encodeBase64(encrypted)); return encryptedString; } public static String decrypt (String encryptedString) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException, IOException, ClassNotFoundException, UnsupportedEncodingException, DecoderException{ PBEParameterSpec pbeParamSpec = new PBEParameterSpec(salt, 10); PBEKeySpec pbeKeySpec = new PBEKeySpec(S); SecretKeyFactory factory = SecretKeyFactory.getInstance("PBKDF2WithHmacSHA1"); SecretKey key = factory.generateSecret(pbeKeySpec); Cipher c = Cipher.getInstance("PBEWithMD5AndDES"); c.init(Cipher.ENCRYPT_MODE,key,pbeParamSpec); byte[] encryptedText = Base64.decodeBase64(encrypt(secretData)); byte[] plainText = c.doFinal(encryptedText); String decryptedText= new String(plainText); System.out.println(decryptedText); return decryptedText; } public static void main(String args[]) throws Exception { passphrase p= new passphrase(); } }
I get this frustrating output(Exception in
thread
"main" java.security.spec.InvalidKeySpecException: Salt not found)
Why is That?
Thank you all
You would be much easier to understand if you took that bucket off of your head. And that goes for the tiny ad too!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Store HTTPS file upload on server encrypted?
InvalidKeyException
File encryption / decryption retaining line feeds
program that uses Bouncycastle throws an exception of illegal key size
AES Encryption Service
More...