Skip to content

Instantly share code, notes, and snippets.

@CCob
Created January 28, 2021 20:09
Show Gist options
  • Select an option

  • Save CCob/9dd8de00c2c6ad069301a225589223fa to your computer and use it in GitHub Desktop.

Select an option

Save CCob/9dd8de00c2c6ad069301a225589223fa to your computer and use it in GitHub Desktop.

Revisions

  1. CCob created this gist Jan 28, 2021.
    47 changes: 47 additions & 0 deletions rc4.cna
    Original 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];
    }