npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xor-encryption

v1.0.0

Published

Encrypt and decrypt string data using the XOR encryption method to make it easier.

Downloads

273

Readme

xor-encryption

Encrypt and decrypt string data using the XOR encryption method to make it easier.

Install

  1. Via NPM : npm i xor-encryption
  2. Via Yarn : yarn add xor-encryption

Import

  1. CJS : const { encryptFromString, decryptFromHex } = require('xor-encryption')
  2. ESM : import { encryptFromString, decryptFromHex } from 'xor-encryption'

Use library on JavaScript / TypeScript

A. encryptFromString

    import { encryptFromString } from 'xor-encryption';
    // if use commonjs use this :
    // const { encryptFromString } = require('xor-encryption');

    // example data and key
    const text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
    const ket = 'secret_key';

    // example function for test
    function test(){
        console.log(encryptFromString(data, key));
    }
    test();

    // result will be like
    // {
    //     original_data_hex: '0x4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f726520657420646f6c6f7265206d61676e6120616c697175612e',
    //     encrypted_data_hex: '0xaeaddfcd73cce37e40bbc187304afb71ede938b106ec028fb3d232e8d4000079bcb79494698671459c252d53f7c38ec0cada4739f024d284f0387b1917a9cf1743ab90c53a80415a0032fb0dae12f539a3170376f259bc9f3148bb55b9366e8cdbc377b93aadbee756b9e48a399fd3b47510bea9d763b6759ee242',
    //     encrypted_data_key_hex: '0x3cc963733f9fa1f6b6ab36672002b216c9b43243ff812364f57df5b3d135bc41'
    // }

B. decryptFromHex

    import { decryptFromHex } from 'xor-encryption';
    // if use commonjs use this :
    // const { decryptFromHex } = require('xor-encryption');

    // example encrypted data and key on hex
    const data = '0xaeaddfcd73cce37e40bbc187304afb71ede938b106ec028fb3d232e8d4000079bcb79494698671459c252d53f7c38ec0cada4739f024d284f0387b1917a9cf1743ab90c53a80415a0032fb0dae12f539a3170376f259bc9f3148bb55b9366e8cdbc377b93aadbee756b9e48a399fd3b47510bea9d763b6759ee242';
    const key = '0x3cc963733f9fa1f6b6ab36672002b216c9b43243ff812364f57df5b3d135bc41';

    // example function for test
    function test(){
        console.log(decryptFromHex(data, key));
    }
    test();

    // result will be like
    // {
    //     decrypted_data_hex: '0x4c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742c2073656420646f20656975736d6f642074656d706f7220696e6369646964756e74207574206c61626f726520657420646f6c6f7265206d61676e6120616c697175612e',
    //     decrypted_data: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.'
    // }

Use library on Solidity

You can import this library into Solidity with the example:

import "xor-encryption/dist/contracts/XOREncryption.sol";

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.24;

contract EncryptDecrypt {
    function decrypt(
        bytes memory data,
        bytes memory key
    ) public pure returns (string memory) {
        return string(XOREncryption.encryptDecrypt(data, key));
    }

    function encrypt(
        string memory data,
        bytes memory key
    ) public pure returns (bytes memory) {
        return XOREncryption.encryptDecrypt(bytes(data), key);
    }
}

Learn more in the examples section.