Created
January 28, 2021 20:09
-
-
Save CCob/9dd8de00c2c6ad069301a225589223fa to your computer and use it in GitHub Desktop.
Revisions
-
CCob created this gist
Jan 28, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,47 @@ #RC4 encryption implementation using Java Crypto API #Author: @_EthicalChaos_ import javax.crypto.spec.*; import java.security.*; import javax.crypto.*; # $1 = plaintext, $2 = key sub encryptRC4{ $cipher = [Cipher getInstance: "RC4"]; $key = [new SecretKeySpec: $2, "RC4"]; [$cipher init: [Cipher ENCRYPT_MODE], $key]; return [$cipher doFinal: $1]; } sub decryptRC4{ $cipher = [Cipher getInstance: "RC4"]; $key = [new SecretKeySpec: $2, "RC4"]; [$cipher init: [Cipher DECRYPT_MODE], $key]; return [$cipher doFinal: $1]; } # $1 = transformation, $2 = key, $3 = iv, $4 = data sub encryptData{ $iv = $null; $cipher = [Cipher getInstance: $1]; $algo = split('/', $1)[0]; $key = [new SecretKeySpec: $2, $algo]; if($3 != $null) $iv = [new IvParametersSpec: $3]; if($iv != $null) [$cipher init: [Cipher ENCRYPT_MODE], $key, $iv]; else [$cipher init: [Cipher ENCRYPT_MODE], $key, $iv]; return [$cipher doFinal: $1]; }