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

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)

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?

I think the password must be number. Ex: 1247980375091875908431789013789013578901759.
Worked for me.

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

Related

MongoDB Compass can't connect to db because Password contains unescaped characters

I have mongo db credentials that have a [ in it. I am getting an error that says "Password contains unescaped characters". I don't know how to rectify while keeping the password the change. Any help on this would be greatly appreciated.
It happened to me today.
Just replace the unescaped characters with the escaped code. It works.
https://docs.microfocus.com/OMi/10.62/Content/OMi/ExtGuide/ExtApps/URL_encoding.htm

Base64 Encoding difference in a particular String

I have a doubt. It's regarding Base64 encoding of one particular String.
We have an application which allows REST WebServices to be executed after authorization of type Basic Authentication is successful.
I has set the password for a user USER_NAME with the password CP#5N0v22nD17RrV8f4​.
From my system, using Postman/Advanced REST client, the request sent is processed successfully. But the same request fails when made most of the other systems using the same REST client.
When I set this password to another user, that user credentials is facing the same problem.
I noticed that the Base64 encoding Output Charset is the problem. But there is no method to change it in the REST clients (not in the most of the ready-made ones).
But why is this happening only for this particular password. I check with every other passwords and it works fine.
String: USER_NAME:CP#5N0v22nD17RrV8f4​
UTF-8: VVNFUl9OQU1FOkNQQDVOMHYyMm5EMTdSclY4ZjTigIs=
Windows-1252: VVNFUl9OQU1FOkNQQDVOMHYyMm5EMTdSclY4ZjQ=
ASCII: VVNFUl9OQU1FOkNQQDVOMHYyMm5EMTdSclY4ZjQ=
Only for CP#5N0v22nD17RrV8f4​ the UTF-8 output charset encoding in Base64 is giving a different result.
Using any other passwords, all the outputs are the same.
Please make me understand why CP#5N0v22nD17RrV8f4​ is different from the rest of the strings.
Thanks in Advance
Balu
The string has a non breaking space at the end of the string.
I tested this using the following steps.
Decoded the UTF-8 string VVNFUl9OQU1FOkNQQDVOMHYyMm5EMTdSclY4ZjTigIs= at https://www.base64decode.org/
Copied the result to encode in UTF-8 at https://www.base64decode.org/, but this time pressed backspace once at the end of string. Gives me output VVNFUl9OQU1FOkNQQDVOMHYyMm5EMTdSclY4ZjQ=
You could also try typing the characters manually, and encoding.

I keep getting syntax errors with my new vBulletin Install

Here is one of many errors I keep getting.
Parse error: syntax error, unexpected 'Database' (T_STRING) in /home2/craven/public_html/forums/core/includes/config.php on line 39
Make sure, you use the correct singlequotes in the config file.
These are correct: 'string', "string"
These are wrong: ´string´, string
You could try to replace all singlequotes with the correct double-quotes, just in case there is something funky going on with encoding in your file.
Also, make sure there are no spaces or newlines between the $config[...] definitions which might break the syntax parser.
Maybe check if the config.php file has the correct encoding, UTF-8 or any latin encodings if you're using european special characters for example. You can use a text editor like Notepad++ to check/modify the file encoding and re-upload the updated file afterwards.
If it still fails, you need to provide information about your webserver system, like the PHP version.

Winjs, error reading file with FileIO.readTextAsync

I am reading a .json file from disk using Windows.Storage.FileIO.readTextAsync.
All is fine until I put some non english letters in the file, like Æ Å Ø
The error I get is (rough translation from Danish language):
WinRT: No mapping for the Unicode character exists in the target multi-byte code page.
any idea how to read those chars in WinJs?
I found the problem.
when I created the file manually with notepad I set it to type ANSII instead of utf8.
I reopened the file -> save as and the changed the type and overwrote it.
You may be able to solve this by changing the encoding from the default (Utf8) to Utf16. The readTextAsync method accepts a second parameter which is a UnicodeEncoding flag:
Windows.Storage.FileIO.readTextAsync(
file,
Windows.Storage.Streams.UnicodeEncoding.utf16LE
).done( ... );
Or if you need to, you can use utf16BE flag (see link above).

Escape FTP password with special characters via CLI

Trying to use Grunt FTP deploy plugin. Have an FTP password with the characters !,#,%,# and can't seem to find which of and how these need to be escaped.
I've tried wrapping the entire password string in single-quotes and \ escaping each character. In the former case I still get and auth failed error; in the latter case, I get an error like "Unexpected token #".
README.md
IMPORTANT: make sure that the .ftppass file uses double quotes (which is the proper JSON syntax) instead of single quotes for the
names of the keys and the string values.
String
Series of characters (letters, numbers, or symbols); double-quoted
UTF-8 with backslash escaping.
I know it is an old question but I just had this problem and finally found a solution.
My CLI is Windows and my problem was related a batch script where the password for my SFTP (using PSFTP) had special charachters.
I solved it escaping the password with the rules described here:
https://www.robvanderwoude.com/escapechars.php
The password was "X5d2KeY6%0123ghjy".
The password became "X5d2KeY6%%0123ghjy" (that is, % became %%).