forked from 2dust/v2rayNG
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a90965
commit 172d6d5
Showing
18 changed files
with
313 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 0 additions & 13 deletions
13
V2rayNG/app/src/androidTest/java/com/v2ray/ang/ApplicationTest.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package SpeedUpVPN | ||
|
||
import android.os.Build | ||
import android.support.annotation.RequiresApi | ||
import android.util.Log | ||
import java.io.File | ||
import javax.crypto.Cipher | ||
import javax.crypto.spec.IvParameterSpec | ||
import javax.crypto.spec.SecretKeySpec | ||
|
||
|
||
object VpnEncrypt{ | ||
private const val theKey="your key" | ||
const val vpnRemark="v2ray.vpn" | ||
val vpnGroupName="SpeedUp.VPN" | ||
@JvmField var builtinServersUpdated=false | ||
@JvmField var builtinSubID="999" | ||
@JvmStatic fun aesEncrypt(v:String, secretKey:String=theKey) = AES256.encrypt(v, secretKey) | ||
@JvmStatic fun aesDecrypt(v:String, secretKey:String=theKey) = AES256.decrypt(v, secretKey) | ||
@JvmStatic fun readFileAsTextUsingInputStream(fileName: String) = File(fileName).inputStream().readBytes().toString(Charsets.UTF_8) | ||
} | ||
|
||
|
||
private object AES256{ | ||
private fun cipher(opmode:Int, secretKey:String):Cipher{ | ||
if(secretKey.length != 32) throw RuntimeException("SecretKey length is not 32 chars") | ||
val c = Cipher.getInstance("AES/CBC/PKCS5Padding") | ||
val sk = SecretKeySpec(secretKey.toByteArray(Charsets.UTF_8), "AES") | ||
val iv = IvParameterSpec(secretKey.substring(0, 16).toByteArray(Charsets.UTF_8)) | ||
c.init(opmode, sk, iv) | ||
return c | ||
} | ||
fun encrypt(str:String, secretKey:String):String{ | ||
val encrypted = cipher(Cipher.ENCRYPT_MODE, secretKey).doFinal(str.toByteArray(Charsets.UTF_8)) | ||
var encstr: String | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || isWindows()) | ||
encstr = java.util.Base64.getEncoder().encodeToString(encrypted) | ||
else | ||
encstr = android.util.Base64.encodeToString(encrypted, android.util.Base64.DEFAULT) | ||
|
||
return encstr | ||
} | ||
fun decrypt(str:String, secretKey:String):String{ | ||
try { | ||
val byteStr: ByteArray; | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O || isWindows()) | ||
byteStr = java.util.Base64.getDecoder().decode(str.toByteArray(Charsets.UTF_8)) | ||
else | ||
byteStr = android.util.Base64.decode(str.toByteArray(Charsets.UTF_8), android.util.Base64.DEFAULT) | ||
|
||
return String(cipher(Cipher.DECRYPT_MODE, secretKey).doFinal(byteStr)) | ||
} catch (e: Exception) { | ||
Log.e("VpnEncrypt","decrypt failed",e) | ||
return "" | ||
} | ||
} | ||
fun isWindows(): Boolean { | ||
var os= System.getProperty("os.name") | ||
if(os.isNullOrEmpty()) | ||
return false | ||
else | ||
return os.contains("Windows") | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.