JDK-8236400 : java.security.spec.InvalidKeySpecException: Password is not ASCII
  • Type: Bug
  • Component: security-libs
  • Sub-Component: javax.crypto
  • Affected Version: 8u231,11,14
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-12-02
  • Updated: 2025-05-19
  • Resolved: 2025-05-13
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 25
25Resolved
Related Reports
Duplicate :  
Description
A DESCRIPTION OF THE PROBLEM :
Password-Based Encryption causes the following exception when password contains character '§':
java.security.spec.InvalidKeySpecException: Password is not ASCII

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. compile PBERepro.java: javac -d . PBERepro.java
2. run it: java -cp . el.info.pbe PBERepro


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
No exception
ACTUAL -
Exception:
java.security.spec.InvalidKeySpecException: Password is not ASCII
	at com.sun.crypto.provider.PBEKey.<init>(PBEKey.java:65)
	at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(PBEKeyFactory.java:219)
	at javax.crypto.SecretKeyFactory.generateSecret(SecretKeyFactory.java:336)
	at el.info.pbe.PBERepro.main(PBERepro.java:14)

---------- BEGIN SOURCE ----------
package el.info.pbe;

import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;

public class PBERepro {

	public static void main(String[] args) throws Exception {
		String pwdString = "h§o";
		PBEKeySpec pbeKeySpec = new PBEKeySpec(pwdString.toCharArray());
				
		SecretKeyFactory secretKeyFactory = SecretKeyFactory.getInstance("PBEWithHmacSHA512AndAES_128");
		SecretKey pbeKey = secretKeyFactory.generateSecret(pbeKeySpec);
	}
}
---------- END SOURCE ----------

FREQUENCY : always



Comments
https://bugs.openjdk.org/browse/JDK-8348732
13-05-2025

As part of JDK-8348732, we relaxed the ASCII requirement to UTF-8 for SunJCE provider's PBE SKF impl to accept unicode. Thus, this should probably be closed as a dup of that.
30-04-2025

The problem is reproduced with 8u231, 12.0.3, 13.0.1 and 14 ea as well.
19-12-2019