That piece of code does not know how to generate keys. It should certainly not use the proprietary, unspecified "SHA1PRNG"
from Sun (which has different implementations under Android) to derive keys from a password.
The getRawKey
function may generate different keys on different platforms. It may even generate completely random keys each time it is used, depending on the implementation of "SHA1PRNG"
. This means you may never be able to retrieve your plaintext ever again, especially on Android.
If you want to encrypt something with a password, please lookup articles on how to use Password Based Encryption (PBE) where the key derivation is performed using PBKDF2 - present the Oracle Java platform..
Furthermore, the seed seems to use the default character encoding, which might be UTF-16 LE, UTF-16 BE, UTF-8 or some latin based character encoding. It's also using ECB as the "AES"
instance of Cipher
uses ECB by default, so it is not safe for keeping your data confidential.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…