pax_global_header00006660000000000000000000000064146753656730014540gustar00rootroot0000000000000052 comment=14e9cbd1641038efb900ecbef8be7cb7f0781dc7 browserify-browserify-rsa-fe761f2/000077500000000000000000000000001467536567300173315ustar00rootroot00000000000000browserify-browserify-rsa-fe761f2/.eslintrc000066400000000000000000000001231467536567300211510ustar00rootroot00000000000000{ "root": true, "extends": "@ljharb", "rules": { "func-style": "off", }, } browserify-browserify-rsa-fe761f2/.github/000077500000000000000000000000001467536567300206715ustar00rootroot00000000000000browserify-browserify-rsa-fe761f2/.github/FUNDING.yml000066400000000000000000000011111467536567300225000ustar00rootroot00000000000000# These are supported funding model platforms github: [ljharb] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: npm/browserify-rsa community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] browserify-browserify-rsa-fe761f2/.github/SECURITY.md000066400000000000000000000002351467536567300224620ustar00rootroot00000000000000# Security Please email [@ljharb](https://github.com/ljharb) or see https://tidelift.com/security if you have a potential security vulnerability to report. browserify-browserify-rsa-fe761f2/.github/workflows/000077500000000000000000000000001467536567300227265ustar00rootroot00000000000000browserify-browserify-rsa-fe761f2/.github/workflows/node-aught.yml000066400000000000000000000003321467536567300255020ustar00rootroot00000000000000name: 'Tests: node.js < 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 0.10 < 10' type: minors command: npm run tests-only browserify-browserify-rsa-fe761f2/.github/workflows/node-pretest.yml000066400000000000000000000002061467536567300260600ustar00rootroot00000000000000name: 'Tests: pretest/posttest' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/pretest.yml@main browserify-browserify-rsa-fe761f2/.github/workflows/node-tens.yml000066400000000000000000000003241467536567300253440ustar00rootroot00000000000000name: 'Tests: node.js >= 10' on: [pull_request, push] jobs: tests: uses: ljharb/actions/.github/workflows/node.yml@main with: range: '>= 10' type: minors command: npm run tests-only browserify-browserify-rsa-fe761f2/.github/workflows/rebase.yml000066400000000000000000000002571467536567300247160ustar00rootroot00000000000000name: Automatic Rebase on: [pull_request_target] jobs: _: uses: ljharb/actions/.github/workflows/rebase.yml@main secrets: token: ${{ secrets.GITHUB_TOKEN }} browserify-browserify-rsa-fe761f2/.github/workflows/require-allow-edits.yml000066400000000000000000000003031467536567300273430ustar00rootroot00000000000000name: Require “Allow Edits” on: [pull_request_target] jobs: _: name: "Require “Allow Edits”" runs-on: ubuntu-latest steps: - uses: ljharb/require-allow-edits@main browserify-browserify-rsa-fe761f2/.gitignore000066400000000000000000000001731467536567300213220ustar00rootroot00000000000000node_modules npm-debug.log # Only apps should have lockfiles npm-shrinkwrap.json package-lock.json yarn.lock .npmignore browserify-browserify-rsa-fe761f2/.npmrc000066400000000000000000000000671467536567300204540ustar00rootroot00000000000000package-lock=false allow-same-version=true message=v%s browserify-browserify-rsa-fe761f2/CHANGELOG.md000066400000000000000000000135541467536567300211520ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [v4.1.1](https://github.com/browserify/browserify-rsa/compare/v4.1.0...v4.1.1) - 2024-09-26 ### Commits - Only apps should have lockfiles [`9d8732b`](https://github.com/browserify/browserify-rsa/commit/9d8732b17f25a24aa1c367bf244c1e95f3a4c485) - [eslint] switch to eslint [`7e391c4`](https://github.com/browserify/browserify-rsa/commit/7e391c4dec3407ca1a7af4284f2c5f8c4a745ff2) - [meta] add `auto-changelog` [`2e3fdef`](https://github.com/browserify/browserify-rsa/commit/2e3fdeff72d0695b7d9b4b6dc056404ad1d9da96) - [Tests] migrate from travis to GHA [`9d29368`](https://github.com/browserify/browserify-rsa/commit/9d29368f3b76a808cc7575533b135b113c96a219) - [Tests] improve test organization [`21b8fe5`](https://github.com/browserify/browserify-rsa/commit/21b8fe58085fed8f0b8bd2f111f25079152fa905) - [Tests] `crypto.privateDecrypt` is only in node 0.12+ [`52a4253`](https://github.com/browserify/browserify-rsa/commit/52a4253a5f5b19401bab450f2f29e68480c56077) - [meta] add `npmignore` and `safe-publish-latest` [`bd5d1c2`](https://github.com/browserify/browserify-rsa/commit/bd5d1c222daafeb2121b2b79b8feb536b565f4e7) - [Fix] use `safe-buffer` [`28d2560`](https://github.com/browserify/browserify-rsa/commit/28d256045487adb3b88f7b958fa6728702f9f4f6) - [meta] add `exports` [`50464d7`](https://github.com/browserify/browserify-rsa/commit/50464d70d37a1c771268cd336de6424eafa4f42d) - [Deps] update `bn.js`, `randombytes` [`d833e49`](https://github.com/browserify/browserify-rsa/commit/d833e49e520f502cf8dfce1fe159041b6a1c6005) - [meta] raise `engines.node` to 0.10, due to `parse-asn1` [`063d27b`](https://github.com/browserify/browserify-rsa/commit/063d27b4476dd7d833a57014cf9c6c786005c5dd) - [Dev Deps] update `parse-asn1`, `tape` [`7d19782`](https://github.com/browserify/browserify-rsa/commit/7d197823631bcb274efe52970af0f42188b9b7fe) - [meta] add missing `engines.node` [`a2e5e94`](https://github.com/browserify/browserify-rsa/commit/a2e5e9411b902439afb1fd9e61d853469a6d1a59) - [meta] correct git URL [`f235983`](https://github.com/browserify/browserify-rsa/commit/f23598305d24c2fb1c76f582b1cb22ffba20f374) - [Dev Deps] add missing deps from 2e3fdef [`5ea31da`](https://github.com/browserify/browserify-rsa/commit/5ea31da9edf0ec7788c0361bc1a8a90b040f6fe2) - [meta] add `sideEffects` flag [`4a2d873`](https://github.com/browserify/browserify-rsa/commit/4a2d8730ea1725651103b0970a6af0b3871fd9be) ## [v4.1.0](https://github.com/browserify/browserify-rsa/compare/v4.0.1...v4.1.0) - 2020-11-12 ### Merged - bump bn.js to 5.0.0 [`#13`](https://github.com/browserify/browserify-rsa/pull/13) - update loop in ger [`#10`](https://github.com/browserify/browserify-rsa/pull/10) ### Commits - update tests [`7b34cc7`](https://github.com/browserify/browserify-rsa/commit/7b34cc75cda375fcfb2577f6c2334b273728a632) - update index.js [`6c2c290`](https://github.com/browserify/browserify-rsa/commit/6c2c290a5b3af41f8a2f68ca7f8d340bfb6d38ec) - update package.json [`9f906f8`](https://github.com/browserify/browserify-rsa/commit/9f906f8f76fcbca9f0c0a412f76eab03b01976cc) - update README.md [`f55b31a`](https://github.com/browserify/browserify-rsa/commit/f55b31aa0d15a7bf1dd6dd222314fbd0d7a5fc2e) - update travis config [`7342836`](https://github.com/browserify/browserify-rsa/commit/73428369fe9d976f41cbbac2b60421d65ea60516) - add .gitignore [`d0a4613`](https://github.com/browserify/browserify-rsa/commit/d0a4613bb72d8874171cf9d666ea272cc3c7bc20) ## [v4.0.1](https://github.com/browserify/browserify-rsa/compare/v4.0.0...v4.0.1) - 2016-02-26 ### Merged - package.json: fix repository URL [`#8`](https://github.com/browserify/browserify-rsa/pull/8) ## [v4.0.0](https://github.com/browserify/browserify-rsa/compare/v3.0.0...v4.0.0) - 2015-10-29 ### Merged - bump bn.js and parse-asn1 [`#6`](https://github.com/browserify/browserify-rsa/pull/6) ### Commits - fix dev dep [`3acf6c7`](https://github.com/browserify/browserify-rsa/commit/3acf6c7729e254429cb6485747ebf54fa9ccfb29) ## [v3.0.0](https://github.com/browserify/browserify-rsa/compare/v2.0.1...v3.0.0) - 2015-10-26 ### Merged - bump bn-js [`#5`](https://github.com/browserify/browserify-rsa/pull/5) - Adding license and updating package.json [`#4`](https://github.com/browserify/browserify-rsa/pull/4) ### Commits - Add LICENSE [`3ee2b4d`](https://github.com/browserify/browserify-rsa/commit/3ee2b4d3428c9504860e62d7c070d75dd2710f48) - package: adds description [`af8556a`](https://github.com/browserify/browserify-rsa/commit/af8556a0d5355f6921dbdfee4bf4ff1190b05c10) ## [v2.0.1](https://github.com/browserify/browserify-rsa/compare/v2.0.0...v2.0.1) - 2015-05-20 ### Merged - update bn.js [`#3`](https://github.com/browserify/browserify-rsa/pull/3) ### Commits - Fix badge URL to point to crypto-browserify org [`823888a`](https://github.com/browserify/browserify-rsa/commit/823888a93b513724a43e0d56bfe9c951e84c0e60) - update readme [`0f404ac`](https://github.com/browserify/browserify-rsa/commit/0f404ac2235c4fa4a2124a29cb6cd9a6dbb25d22) ## [v2.0.0](https://github.com/browserify/browserify-rsa/compare/v1.2.0...v2.0.0) - 2015-01-28 ## [v1.2.0](https://github.com/browserify/browserify-rsa/compare/v1.1.1...v1.2.0) - 2015-01-28 ### Commits - modularize [`de640bf`](https://github.com/browserify/browserify-rsa/commit/de640bff7f5fcdc1ed68ce420d972c5c4005f70f) ## v1.1.1 - 2015-01-06 ### Commits - left pad here and clean up tests [`240e16c`](https://github.com/browserify/browserify-rsa/commit/240e16c3b116dca1a63e463f494bd3447abb3b8a) - first [`ceb731f`](https://github.com/browserify/browserify-rsa/commit/ceb731f7d56e4aba5440b99709dda6c2cb38b5dc) - Update bn.js [`dfcf387`](https://github.com/browserify/browserify-rsa/commit/dfcf38757fc28a7d929a208f1775c59c9ab7f008) browserify-browserify-rsa-fe761f2/LICENSE000066400000000000000000000021151467536567300203350ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2014-2016 Calvin Metcalf & contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. browserify-browserify-rsa-fe761f2/README.md000066400000000000000000000013121467536567300206050ustar00rootroot00000000000000# browserify-rsa [![NPM Package](https://img.shields.io/npm/v/browserify-rsa.svg?style=flat-square)](https://www.npmjs.org/package/browserify-rsa) [![Build Status](https://img.shields.io/travis/crypto-browserify/browserify-rsa.svg?branch=master&style=flat-square)](https://travis-ci.org/crypto-browserify/browserify-rsa) [![Dependency status](https://img.shields.io/david/crypto-browserify/browserify-rsa.svg?style=flat-square)](https://david-dm.org/crypto-browserify/browserify-rsa#info=dependencies) RSA private decryption/signing using chinese remainder and blinding. ## API Give it a message as a Buffer and a private key (as decoded by `ASN.1`) and it returns encrypted data as a Buffer. ## LICENSE MIT browserify-browserify-rsa-fe761f2/index.js000066400000000000000000000021651467536567300210020ustar00rootroot00000000000000'use strict'; var BN = require('bn.js'); var randomBytes = require('randombytes'); var Buffer = require('safe-buffer').Buffer; function getr(priv) { var len = priv.modulus.byteLength(); var r; do { r = new BN(randomBytes(len)); } while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)); return r; } function blind(priv) { var r = getr(priv); var blinder = r.toRed(BN.mont(priv.modulus)).redPow(new BN(priv.publicExponent)).fromRed(); return { blinder: blinder, unblinder: r.invm(priv.modulus) }; } function crt(msg, priv) { var blinds = blind(priv); var len = priv.modulus.byteLength(); var blinded = new BN(msg).mul(blinds.blinder).umod(priv.modulus); var c1 = blinded.toRed(BN.mont(priv.prime1)); var c2 = blinded.toRed(BN.mont(priv.prime2)); var qinv = priv.coefficient; var p = priv.prime1; var q = priv.prime2; var m1 = c1.redPow(priv.exponent1).fromRed(); var m2 = c2.redPow(priv.exponent2).fromRed(); var h = m1.isub(m2).imul(qinv).umod(p).imul(q); return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer, 'be', len); } crt.getr = getr; module.exports = crt; browserify-browserify-rsa-fe761f2/package.json000066400000000000000000000032531467536567300216220ustar00rootroot00000000000000{ "name": "browserify-rsa", "version": "4.1.1", "description": "RSA for browserify", "bugs": { "url": "https://github.com/crypto-browserify/browserify-rsa/issues" }, "license": "MIT", "main": "index.js", "exports": { ".": "./index.js", "./package.json": "./package.json" }, "sideEffects": false, "repository": { "type": "git", "url": "https://github.com/crypto-browserify/browserify-rsa.git" }, "scripts": { "prepack": "npmignore --auto --commentLines=autogenerated", "prepublish": "not-in-publish || npm run prepublishOnly", "prepublishOnly": "safe-publish-latest", "lint": "eslint --ext=js,mjs .", "pretest": "npm run lint", "test": "npm run tests-only", "tests-only": "tape 'test/**/*.js'", "posttest": "npx npm@'>=10.2' audit --production", "version": "auto-changelog && git add CHANGELOG.md", "postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\"" }, "dependencies": { "bn.js": "^5.2.1", "randombytes": "^2.1.0", "safe-buffer": "^5.2.1" }, "devDependencies": { "@ljharb/eslint-config": "^21.1.1", "auto-changelog": "^2.5.0", "encoding": "^0.1.13", "eslint": "=8.8.0", "in-publish": "^2.0.1", "npmignore": "^0.3.1", "parse-asn1": "^5.1.7", "safe-publish-latest": "^2.0.0", "tape": "^5.9.0" }, "engines": { "node": ">= 0.10" }, "auto-changelog": { "output": "CHANGELOG.md", "template": "keepachangelog", "unreleased": false, "commitLimit": false, "backfillLimit": false, "hideCredit": true }, "publishConfig": { "ignore": [ ".github/workflows", "test", ".eslintrc", ".github" ] } } browserify-browserify-rsa-fe761f2/test/000077500000000000000000000000001467536567300203105ustar00rootroot00000000000000browserify-browserify-rsa-fe761f2/test/fixtures.json000066400000000000000000000153661467536567300230670ustar00rootroot00000000000000[ "2d2d2d2d2d424547494e2050524956415445204b45592d2d2d2d2d0a4d494943647749424144414e42676b71686b6947397730424151454641415343416d457767674a6441674541416f4742414b756c55545a3842317163635a38630a44585247535930386757384b764c6c63787878474334675a484e543343425546386e3552344b453330615a79595a2f727473515a7530356a755a4a78614a30710a6d62653735646c5135642b586339424d586551672f4d70545a773554414e374f4964475959704642652b31504c5a367745666a6b59724d714d55636671324c710a68544c64416276424a6e755263595a4c716d42654f51384654724b7241674d4241414543675945416e6b485262455055332f57495353517250333669794362320a532f53425a774b6b7a6d764372427844576850654473777039632f324a593736724e57664c7a793869586755473857557a76486a653631516833676d42634b650a62556154476c34567938486131594241446f3552665272646d3046453474766776752f546b7146717042425a7765753534323835686b357a6c47376e2f4437590a646e4e58557075354d6c4e623578336757306b43515144554c2f2f637763585578592f6576614a50346a53652b5a7745515a6f2b7a58524c695055756c426f560a6177323843564d757864677771416f315831494b65665065556166375251753867434b61526e704775457558416b45417a785a54664d6d766d435544496577340a35476b36624b3236355851576468636769713235346c7042474f596d446a397943453779412b7a6d415351774d73585464514f6931684f434579725875534a350a632b2b4544514a4146683357726e7a6f455042797559584d6d45543874534652574d51357670674e716833686148523562346755433268786169756e43424e4c0a315270565939416f55694479774763472f5350683933436e4b42336e69774a42414b503741747369665a6756587469697a4234614d5468546a565961535a727a0a44304b6739447548796c706b4443686d467537375447724e55516741567559746668622f6252626c56612f4630684a3465514854334a554351425654363874620a4f6752556b30615039744333303231564e383258362b6b6c6f7753514e386f425058382b546644575355696c702f2b6a3234486b792b5a3239446f3779522f520a7175746e4c39324376426c564c56343d0a2d2d2d2d2d454e442050524956415445204b45592d2d2d2d2d0a", "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949435641494241414a2f4f77737762466f2f757943386c7447662f794131412b6756354947646e4167506255534933477a624843412b782b544c472f744c0a76625277337231736d7070592f6a6b6b70695657314572534d754e307569787035676237385a39724831587057623557576770335761592f3945484d6a4d644f0a6b512f394c565a7652766c2f4d2f4669366f77502b712b616d4a493142456a454359666268474c33726d6c5664713471586334305177494441514142416e38490a565a3042506f414f68794633334b464d4878793872323866735667784a5559674d334e715167647634664661774359586a684a7a3964755535594a47464a474a0a57554765486c6b7959466c70693466336d377459374a61776d51555742304d4e536f4b48493363674458342f7466424e386e692b634f3065536f5235637a42590a4573414842553437703161774e46414877642b5a457576394834526d4d6e37703237397251547470416b4148334e7173322f7672524632635a554e34664958660a347848735142427955617947713861334a305547615346577636387a54554b466865727239755a6f744e70374e4a346a425869415277307138646f63585547310a416b4148676d4f4b486f4f5274416d696b71706d46454a5a4f7473584d614c43496d3445737a506f356369596f4c4d42635669743039416469516c74375a4a4c0a445930327376553162306167435a39376b446b6d48446b58416b414361384d394a454c7544732f502f76494759446b4d566174494666573662574630326546470a746157774d71436353457357766277307871597433346a5552704e62436a6d4379515677596641772f2b544c68503964416b414677526a64776a77333771706a0a646467316d4e697533376237737746786d6b694d4f585a5278614e4e736662353641313452704e337a6f6233516447557962476f644d494b5446626d552f6c750a436a71417861664a416b41473279663652576277464957664d7974375759436830566147424363677935373441696e566965456f335a5a7946664336332b786d0a33756f614e7934694c6f4a763447436a7155427a335a666356614f2f444457470a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a", "2d2d2d2d2d424547494e205253412050524956415445204b45592d2d2d2d2d0a4d4949456a77494241414b422f6779376d6a615767506546645659445a5752434139424e69763370506230657332372b464b593068737a4c614f7734374578430a744157704473483438545841667948425977424c67756179666b344c4749757078622b43474d62526f337845703043626659314a62793236543976476a5243310a666f484444554a4738347561526279487161663469367a74346756522b786c4145496a6b614641414b38634f6f58415431435671474c4c6c6a554363684c38500a6a61486a2f7972695a2f53377264776c49334c6e41427877776d4c726d522f7637315774706d4f2f614e47384e2b31706f2b5177616768546b79513539452f5a0a7641754f6b4657486f6b32712f523650594161326a645a397a696d3046714f502b6e6b5161454452624246426d4271547635664647666b32577341664b662f520a47302f5646642b5a654d353235315465547658483639356e6c53476175566c3941674d42414145436766344c725748592f6c35346f7554685a577676627275670a70667a36734a583267396c3779586d576c455773504543566f2f375355627059467074364f5a7939397a53672b494b624771574b6664686f4b725477495674430a4c30595a304e6c6d646e414e53497a30726f785147375a786b4c352b764853772f506d443978345577662b437a38684154436d4e42763171633630646b7975570a34434c71653732716154695657526f4f316961675167684e634c6f6f36765379363545784c614344545068613779753276773468465a705769456a57346478660a7246644c696978353242433836596c416c784d452f724c6738494a5676696c62796f39615764586d784f6155544c527636506b4644312f6756647738563951720a534c4e39466c4b326b6b6a695830647a6f6962765a7733744d6e74337979644178305838372b734d5256616843316270336b56507a3448793045575834514a2f0a504d33317647697549546b324e43643531445874314c746e324f503546614a536d4361456a6830586b5534716f7559796a585774384275364254436c327675610a466730556a6939432b496b504c6d61554d624d494f7761546b386357714c74685378734c6537304a354f6b477267664b554d2f772b4248483150742f506a7a6a0a432b2b6c306b6946614f5644566141563947704c504c43426f4b2f50433952622f72784d4d6f43434e774a2f4e5a756564496e793277334c4d69693737682f540a7a53766572674e47686a5936526e7661386c4c584a36646c726b6350417970733367577778716a344e5230542b474d3062445550564c62374d303758563753580a7637564a476d35324a625247774d3173732b72385854544e656d65476b2b5752784737546774734d715947584c66423851786b2f66352f4d63633030546c38750a7758464e7366784a786d7436416273547233673336774a2f49684f6e69627a3941642b6e63686c426e4e3351655733434b48717a61523138766f717674566d320a6b4a66484b31357072482f7353476d786d6945476772434a545a78744462614e434f372f56426a6e4b756455554968434177734c747571302f7a7562397641640a384731736366497076357161534e7a6d4b6f5838624f77417276725336775037794b726354737557496c484438724a5649374945446e516f5470354738664b310a68774a2f4d4968384d35763072356455594576366f494a5747636c65364148314a6d73503557496166677137325a32323838704863434648774e59384467394a0a3736517377564c6e556850546c6d6d33454f4f50474574616d32694144357230416679746c62346c624e6f51736a32737a65584f4e4458422b366f7565616a680a564e454c55723848635350356c677a525a6a4a57366146497a6a394c44526d516e55414f6a475358564f517445774a2f4d43515a374e2f763464494b654452410a3864385545785a332b674748756d7a697a7447524a30745172795a483250616b50354937562b316c377145556e4a3263336d462b65317634314570394c4376680a627a72504b773964786831386734622b37624d707357506e7372614b6836697078633761614f615a5630447867657a347a635a753050316f6c4f30634e334b4d0a6e784a305064733352386241684e43446453324a5a61527035513d3d0a2d2d2d2d2d454e44205253412050524956415445204b45592d2d2d2d2d0a" ] browserify-browserify-rsa-fe761f2/test/index.js000066400000000000000000000027641467536567300217660ustar00rootroot00000000000000'use strict'; var crypto = require('crypto'); var constants = require('constants'); var parseKey = require('parse-asn1'); var BN = require('bn.js'); var Buffer = require('safe-buffer').Buffer; var test = require('tape'); var crt = require('../'); var fixtures = require('./fixtures'); test('browserify-rsa', function (t) { fixtures.forEach(function (fixture, i) { var key = new Buffer(fixture, 'hex'); var priv = parseKey(key); t.test('fixture ' + (i + 1), function (st) { var r; for (var j1 = 1; j1 < 31; ++j1) { r = crt.getr(priv); st.equal( String(r.gcd(priv.modulus)), '1', 'r is coprime with n ' + (i + 1) + ' run ' + j1 ); } st.test('compared to node encryption', { skip: !crypto.privateDecrypt }, function (s2t) { var len = priv.modulus.byteLength(); for (var j2 = 1; j2 < 41; ++j2) { do { r = new BN(crypto.randomBytes(len)); } while (r.cmp(priv.modulus) >= 0); var buf = r.toArrayLike(Buffer, 'be'); if (buf.byteLength < priv.modulus.byteLength()) { var tmp = new Buffer(priv.modulus.byteLength() - buf.byteLength); tmp.fill(0); buf = Buffer.concat([tmp, buf]); } var nodeEncrypt = crypto.privateDecrypt({ padding: constants.RSA_NO_PADDING, key: key }, buf).toString('hex'); s2t.equal( crt(buf, priv).toString('hex'), nodeEncrypt, 'round trip key ' + (i + 1) + ' run ' + j2 + ' equal encrypts' ); } s2t.end(); }); st.end(); }); }); });