'How to resolve java.security.spec.InvalidKeySpecException: Password is not ASCII

I have one test named test_PBE_Triple_DES, here I am using PBE_DES3_CBC_SHA1_ALGORITHM to decode the encrypted password but whenever I try to execute it I get an error saying that the password is not ascii.

I have provided the stacktrace below.

com.tibco.security.AXSecurityException: java.security.spec.InvalidKeySpecException: Password is not ASCII
    at com.tibco.security.providers.CryptoVendorImpl_j2se.rename(CryptoVendorImpl_j2se.java:205)
    at com.tibco.security.Crypto.rename(Crypto.java:59)
    at com.tibco.security.TestPassword.test_PBE_Triple_DES(TestPassword.java:105)
Caused by: java.security.spec.InvalidKeySpecException: Password is not ASCII
    at com.sun.crypto.provider.PBEKey.<init>(PBEKey.java:64)
    at com.sun.crypto.provider.PBEKeyFactory.engineGenerateSecret(PBEKeyFactory.java:219)
    at javax.crypto.SecretKeyFactory.generateSecret(SecretKeyFactory.java:330)
    at com.tibco.security.providers.CryptoVendorImpl_j2se.rename(CryptoVendorImpl_j2se.java:161)


Solution 1:[1]

In case anyone runs into this, I was reading the password from a file on the system and it had a newline automatically appended at the end of it it by vim. After I turned off the feature off in vim it worked fine.

Here's how to disable new line. How to stop VIM from adding a newline at end of file?

Solution 2:[2]

Yes, In my case there was new line character was appended. Just added trim method and it got resolved

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 C McCoy
Solution 2 Vedant