Questions tagged [javax.crypto]

The javax.crypto package contains standard java classes for various cryptographic operations. It is part of Java SE since version 1.4.

87 questions
144
votes
7 answers

Given final block not properly padded

I am trying to implement password based encryption algorithm, but I get this exception: javax.crypto.BadPaddingException: Given final block not properly padded What might be the problem? Here is my code: public class PasswordCrypter { private…
Altrim
  • 6,536
  • 4
  • 33
  • 36
47
votes
5 answers

How can I list the available Cipher algorithms?

I am getting a Cipher implementation with Cipher.getInstance(String algorithm). I am under the impression that the available algorithm names that I may pass differ based on what libraries which are present in my classpath. I would like to write a…
skiphoppy
  • 97,646
  • 72
  • 174
  • 218
35
votes
2 answers

PBKDF2WithHmacSHA512 Vs. PBKDF2WithHmacSHA1

I'm working on a Java authentication subsystem that specs the storage of passwords in the DB as PBKDF2-generated hashes, and I'm now trying to decide whether I should use SHA1 or SHA512 as PRF. I went through the specs of both but they are very…
DTs
  • 1,196
  • 1
  • 11
  • 28
17
votes
3 answers

Why am I getting package javax.crypto does not exist

When I compile a class using javax.crypto.Mac I get this error message? package javax.crypto does not exist I can fix it by including jre/lib/jce.jar in my compile classpath. Why is jce.jar not on the default jdk classpath? jre/lib/rt.jar is on…
Mike Hogan
  • 9,933
  • 9
  • 41
  • 71
15
votes
2 answers

What's the difference between a Key and a KeySpec?

In the Java crypto libraries, there are two different representations of a key - Key and KeySpec. The docs imply there's a difference between the two - a KeySpec is 'transparent' (whatever that means), but has no methods, whereas Key has got a…
thecoop
  • 45,220
  • 19
  • 132
  • 189
8
votes
1 answer

iOS CryptoKit in Java

I am looking for settings/parameters of CryptoKit which will allow me to share data between iOS App and a Java Application. The flow would be something like below: - Use CryptoKit to encrypt a text using a fixed key and random initialization vector…
Amit Bajaj
  • 171
  • 1
  • 10
6
votes
3 answers

javax.crypto working differently in different versions of Android OS?

I'm using this code snippet to encrypt/decrypt data in my app's database: http://www.androidsnippets.com/encryptdecrypt-strings It appears that the javax.crypto.KeyGenerator.generateKey() operation works differently in Android 2.3.3 OS than in other…
wct097
  • 103
  • 2
  • 9
6
votes
2 answers

javax.crypto.Cipher working differently since Android 6 Marshmallow

I've been successfully using javax.crypto.Cipher.getInstance("DESede/CBC/NoPadding") to Authenticate with DESFire cards on Android (following the example here: https://stackoverflow.com/a/14160507/2095694). It's been working on several devices from…
6
votes
1 answer

Encrypt using OpenSSL in the same way Java does

I have to encrypt an string using bash script in the same way I encrypt using javax.crypto.Cipher. At java I use AES-256 with the key "0123456789". But When I use openssl I had to convert "0123456789" to hex, but the result is not the same of the…
Felipe Gutierrez
  • 525
  • 1
  • 9
  • 20
5
votes
1 answer

PowerMock issues with ssl & StandardPBEStringEncryptor

Was trying to run the Junit tests Below is for the Password decryption using org.jasypt.encryption.pbe.StandardPBEStringEncryptor > Caused by: org.jasypt.exceptions.EncryptionInitializationException: >…
Syed Rafi
  • 825
  • 2
  • 12
  • 35
5
votes
1 answer

GCM encryption and decryption in xws-security (webservices-rt)

I've successfully implemented support for GCM encryption in xws-security (EncryptionProcessor.java) using JDK8 as tested against other systems. However I have a problem with decryption. The first problem was as…
tkr
  • 93
  • 1
  • 6
5
votes
1 answer

Clojure SHA256 HMAC function not producing expected results

I have the following Clojure code: (ns myproject.hmac-sha256 (:import (javax.crypto Mac) (javax.crypto.spec SecretKeySpec))) (defn secretKeyInst [key mac] (SecretKeySpec. (.getBytes key) (.getAlgorithm mac))) (defn toString…
Matthew H
  • 5,831
  • 8
  • 47
  • 82
4
votes
1 answer

javax.crypto in Java 8u20

After JDK update (8u11 -> 8u20) my code stopped compiling. These classes become unavailable: import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; Was javax.crypto package was removed from latest Oracle JDK? I cannot find any…
bigGuy
  • 1,732
  • 1
  • 22
  • 37
4
votes
1 answer

javax.crypto JDK source code, again

I've been looking for the javax.crypto JDK source code and I could not find it. Either this is due to my abject searching inability or there must be a reason why the code is not available (the JDK is supposed to be open source, right?) . My guess…
Andrea Alciato
  • 199
  • 1
  • 11
3
votes
1 answer

Android and Crypto++ AES 128bit encrypted results not matching

I am trying to use the same key and VI to encrypt and decryp the same message, say aabbcc@gmail.com. The key length is 128 bit as I know that in Java/Android, 256 is not easy to implement. Here is my function to do the AES encryption using…
Joe
  • 841
  • 2
  • 10
  • 25
1
2 3 4 5 6