public static KeystoreData Load() { string pathKeyData = GetKeyDataPath(); if (File.Exists(pathKeyData) == false) { return(NewKeystoreData()); } using (FileStream fs = new FileStream(pathKeyData, FileMode.Open, FileAccess.Read)) { if (fs.Length <= 0) { return(NewKeystoreData()); } byte[] bytePrivateKey = new byte[PRIVATE_KEY_LEN]; fs.Read(bytePrivateKey, 0, PRIVATE_KEY_LEN); privateKey = System.Text.Encoding.UTF8.GetString(bytePrivateKey); int readLength = (int)fs.Length - PRIVATE_KEY_LEN; byte[] bytes = new byte[readLength]; fs.Read(bytes, 0, readLength); string encryptData = System.Text.Encoding.UTF8.GetString(bytes); string decryptData = Decrypt(encryptData); KeystoreData keystoreData = JsonUtility.FromJson <KeystoreData>(decryptData); return(keystoreData); } }
static public void AndroidSetting(KeystoreData keystoreData) { PlayerSettings.Android.keystorePass = keystoreData.keystorePass; PlayerSettings.Android.keyaliasName = keystoreData.keyaliasName; PlayerSettings.Android.keyaliasPass = keystoreData.keyaliasPass; #if UNITY_2019 EditorUserBuildSettings.androidReleaseMinification = keystoreData.releaseMinify; #endif }
static void Save(KeystoreData keystoreData) { string jsonString = JsonUtility.ToJson(keystoreData); string encryptString = Encrypt(jsonString); using (FileStream fs = new FileStream(GetKeyDataPath(), FileMode.Create, FileAccess.Write)) { byte[] bytePrivateKey = System.Text.Encoding.UTF8.GetBytes(privateKey); fs.Write(bytePrivateKey, 0, bytePrivateKey.Length); byte[] bytes = System.Text.Encoding.UTF8.GetBytes(encryptString); fs.Write(bytes, 0, bytes.Length); } }
void OnEnable() { _keystoreData = Load(); AndroidSetting(_keystoreData); }