Unable to obtain hash string from RNCryptor.key

35 views
Skip to first unread message

Dolphin7

unread,
Mar 6, 2018, 9:56:48 AM3/6/18
to rncryptor
Hello,

Using the example for hashing a password, in Swift 4 iOS 11 Xcode 9.2. am unable to obtain the hash string after executing RNCryptor.key with the following code:

        let staticSalt = "com.example.mygreatapp"

        let userSalt = "b...@example.org"

        let salt = (staticSalt + userSalt).data(using: String.Encoding.utf8)

        let kDerivationSettings = RNCryptorKeyDerivationSettings(keySize: 32, saltSize: 8, PBKDFAlgorithm: 2, PRF: 3, rounds: 10000, hasV2Password: false)

        let password = "SomethingTheUserTyped"

        let hash = RNCryptor.key(forPassword: password, salt: salt, settings: kDerivationSettings)

            

        print(hash)

        

        let hashS = String(data: hash!, encoding: String.Encoding.utf8)

        

 hashS is nil.


any help would be greatly appreciated. 



Rob Napier

unread,
Mar 6, 2018, 9:59:33 AM3/6/18
to rncr...@googlegroups.com
Answered via GitHub:  https://github.com/RNCryptor/RNCryptor/issues/270

A key is not a UTF-8 string. It’s random data. If you want to encode it into a string, you’ll need to use some kind of encoding such as Base64 or Hex.

-Rob

--
You received this message because you are subscribed to the Google Groups "rncryptor" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rncryptor+...@googlegroups.com.
Visit this group at https://groups.google.com/group/rncryptor.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages