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

squirrel_crypto

v1.0.2

Published

Simples modulo para trabalho com criptografia utilizando nodejs com biblioteca nativa

Downloads

4

Readme

squirrel_crypto

Simples modulo para trabalho com criptografia utilizando nodejs com biblioteca nativa

criptografia symmetrica

const { Asymmetric, Symmetric, Hash } = require('squirrel_crypto')

const symmetric = new Symmetric({
  // informa que deseja que o modulo use hash na senha
  hash: true,
  // informa o algoritmo de hase a ser utilizado
  hashAlgorithm: 'RSA-SHA512',
  // informa o algoritmo de criptografia a ser utilizado
  algorithm: 'aes-256-cbc-hmac-sha256',
  // informa a senha
  passphrase: 'password@teste'
})

// caso não possua um vetor de inicialização
// pode gerar pelo modulo.
// obs: vai ser feito a leitura da configuração do script para obter o tamanho correto.
symmetric.setRandomIv()
const iv = symmetric.getIv()

// encriptando
// o 'base64' é o tipo de saida
const encrypted = symmetric.encrypt('teste', 'base64')
// o 'base64' é o formato de saida da criptografia
// é importante colocar o mesmo formato que foi utilizado na criptografia
const decrypted = symmetric.decrypt(encrypted, 'base64')

console.log(encrypted, decrypted)
// output >> '8eVytOV2/eq6p8VV9hs1wg==' 'teste'

criptografia assymetrica

const { Asymmetric, Symmetric, Hash } = require('squirrel_crypto')

const asymmetric = new Asymmetric({
  // algoritmo a ser utilizado
  algorithm: 'camellia-256-cbc',
  // informa se deseja utilizar o hash na senha fornecida
  hash: true,
  // algoritmo hash
  // vai também ser adicionado ao rsa
  hashAlgorithm: 'ssl3-sha1',
  // tamanho da chave
  keyLength: '2048',
  // senha a ser utilizada
  passphrase: 'password@teste',
  // padding da chave
  rsaPadding: 'RSA_PKCS1_OAEP_PADDING'
});

// obtendo a chave publica e privada
const { publicKey, privateKey } = asymmetric.getKeysPair();

console.log(publicKey, privateKey)
// output >>
/** 
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAuHMwQovWpsWhGnUDbaTdaM2ttzLIuOOiuscNjfyWoYuV8PjaCHJK
j5K8/UeRrYKLkTdBsOsKKhL8Tb3lg4nvwAPgtDDUfZXloSeFTLokr7/xBFqhFmcA
hFD260HpCKl7r940aMIC+HCHvtxmusE8vKuCmM5d2wXbquu0vibdMUC17HdSJrYD
j2DbnsJ50rWMcdXLOcoBbnFEI6KC5Xwgobte2QHfF+GgVheuCQX/boQ4NykFb6RH
ylN02jNchh9JGKxEQEJG/G32b3tDHr7dgbJdgoqmq0BmM4YLFSmRkMDuI7owaHUz
4O6ZzPIq/nFr9GcWVkUG236EILiRE3GX0QIDAQAB
-----END RSA PUBLIC KEY-----
-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFLzBZBgkqhkiG9w0BBQ0wTDApBgkqhkiG9w0BBQwwHAQIB7xiRJSS+ukCAggA
MAwGCCqGSIb3DQIJBQAwHwYLKoMIjJpLPQEBAQQEEPy4DOfFuqEMi5lV8sge99oE
ggTQWklw9UtoyH96fMsX9vsnx8ZFZ+cIoLrju5sCghEU1mLXH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IEOJLMXNUFSqvVHlnBY3WIcMeUcrav2OM3kOSPKCSf
6OEIY1XLtWjP0Wz0McYHuj+3cSpbwGHP5HbdQvRVKKJIKFYhibIstlhxAQYD6mR4
/2sjBqZxXp6/Fn9GZNePHVEkE48fdIqyO4zfemeSG3BKy+xKnTNRMwLNmbf6bBcA
px/MWJNpLjy7Uup7aUoDEXr/BYzu2RvWdOTgvJKX4IV0QiM30qqg3azwNiZEKQmU
N3HQWV1DM0jWgpkFbxKZSIfvu6PHwRVSDKd3xXZzJIwaCIhjnizpnMsEyNRJPkt9
w3jWLQLcmIvdF/coHldqxLJjz9icIRH46Q/HYONcHTPGceoI+EuFSFXNH0GYymkO
7HlfV9tfJ7nCsm+r+lXKCFQuCeEizu+M+EHMq5HJH3v+rUcy4GEyDVwbhyhAHEQ0
k28ABofWEAu8Zzp8HlaeF/4GOPjf3E66bgrl77b2PAPXsgL+8/9oYM7CNum1eZQI
VZo1tlcluSWJpnlYDaq6JRa7+eBIo0Kv4wYrqB1bDo+UJQs=
-----END ENCRYPTED PRIVATE KEY-----
 */

// adiciona as chaves para serem utilizadas na criptografia
// obs: sempre informe uma senha a ser utilizada, o modolo requer uma senha para funcionar caso contrareo pode dar erro, tamém é uma recomendação na documentação oficial.
asymmetric.setPrivateKey(privateKey)
asymmetric.setPublicKey(publicKey)

// 'base64' é o formato de saida
const encrypted = asymmetric.publicEncrypt('teste', 'base64')
// 'base64' é o formato do valor de saida
const decrypted = asymmetric.privateDecrypt(encrypted, 'base64')

console.log(encrypted, decrypted)
// output >> qZbB1y90im4lD+7j80X/Y9hTfu6IttDGuMJXuplTKchAnsvs+GxceeLyuu74kxyYaPtQ10YiiE2KiXOab5DSNtydKDvOq5X7vz9p3IxxmGwnvntBAYpneOIZVfF10P8288XdaogWfI5iEamOT6INUWIuKr3himL3T26W72TS9+BeYJr/w/ksyciAmtm4N7En7SdMlgFX9R6O7ATh/whVCC7njT3PDYzy3rS2i78CtJEW+lNlAwXObCflc7TwnVmqa+GgqgE0ERkx2TenuqU0CAqc8C5RipgPkx1s0IpsmRc3vZ4iqZUKYLxQe9ldqun9t1SvykZmtb0FhOn+jcZ+2w== teste

utilizando hash

const { Asymmetric, Symmetric, Hash } = require('squirrel_crypto')

const hash = new Hash({
  algorithm: 'ssl3-sha1',
  encoding: 'base64'
})

console.log(hash.update('teste valor'))