Using special character as password for keychain via security

I am trying to set up a KeyChain password using the security in my macOS terminal, and it happens that the special characters are encoded and not set to the keychain as it is rather encoded..

When I run this

security add-generic-password -a comp -s example -w 'ã!¼àÁu' -T ""

There will be no error but when the password is called back it is encoded with the something like below

c3a321c2bcc3a0c38175

Does anybody know how i can achieve using this kind of characters without security encoding it as it currently does?

Answered by DTS Engineer in 807169022

That looks right to me. THe first character in your example is ã, or U+00E3 LATIN SMALL LETTER A WITH TILDE. Its UTF-8 encoding is C3 A3, which is the prefix of the result you’re seeing.

What are you actually trying to do here? Keep in mind that a generic password items doesn’t store a string but rather data. If you supply a string on the command line, the security tool has to do some sort of text encoding conversion, to get a data value from the string. It’s chosen to do UTF-8 conversion, which is a good choice IMO.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

That looks right to me. THe first character in your example is ã, or U+00E3 LATIN SMALL LETTER A WITH TILDE. Its UTF-8 encoding is C3 A3, which is the prefix of the result you’re seeing.

What are you actually trying to do here? Keep in mind that a generic password items doesn’t store a string but rather data. If you supply a string on the command line, the security tool has to do some sort of text encoding conversion, to get a data value from the string. It’s chosen to do UTF-8 conversion, which is a good choice IMO.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@DTS Engineer Thank you so much for the response. What I was specifically looking for was to get back exactly this ã!¼àÁu from the security when i call it.

Example Setting

security add-generic-password -a comp -s example -w 'ã!¼àÁu' -T ""

Getting

security find-generic-password -a comp -s example -w
// Should be ã!¼àÁu
// But instead it's c3a321c2bcc3a0c38175

Solution

This is what i ended up doing to convert the response from security back to the original characters

security find-generic-password -a comp -s example -w | xxd -p -r | rev | cut -c 1- | rev
// ã!¼àÁu
Using special character as password for keychain via security
 
 
Q