index.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. 'use strict'
  2. exports.randomBytes = exports.rng = exports.pseudoRandomBytes = exports.prng = require('randombytes')
  3. exports.createHash = exports.Hash = require('create-hash')
  4. exports.createHmac = exports.Hmac = require('create-hmac')
  5. var algos = require('browserify-sign/algos')
  6. var algoKeys = Object.keys(algos)
  7. var hashes = ['sha1', 'sha224', 'sha256', 'sha384', 'sha512', 'md5', 'rmd160'].concat(algoKeys)
  8. exports.getHashes = function () {
  9. return hashes
  10. }
  11. var p = require('pbkdf2')
  12. exports.pbkdf2 = p.pbkdf2
  13. exports.pbkdf2Sync = p.pbkdf2Sync
  14. var aes = require('browserify-cipher')
  15. exports.Cipher = aes.Cipher
  16. exports.createCipher = aes.createCipher
  17. exports.Cipheriv = aes.Cipheriv
  18. exports.createCipheriv = aes.createCipheriv
  19. exports.Decipher = aes.Decipher
  20. exports.createDecipher = aes.createDecipher
  21. exports.Decipheriv = aes.Decipheriv
  22. exports.createDecipheriv = aes.createDecipheriv
  23. exports.getCiphers = aes.getCiphers
  24. exports.listCiphers = aes.listCiphers
  25. var dh = require('diffie-hellman')
  26. exports.DiffieHellmanGroup = dh.DiffieHellmanGroup
  27. exports.createDiffieHellmanGroup = dh.createDiffieHellmanGroup
  28. exports.getDiffieHellman = dh.getDiffieHellman
  29. exports.createDiffieHellman = dh.createDiffieHellman
  30. exports.DiffieHellman = dh.DiffieHellman
  31. var sign = require('browserify-sign')
  32. exports.createSign = sign.createSign
  33. exports.Sign = sign.Sign
  34. exports.createVerify = sign.createVerify
  35. exports.Verify = sign.Verify
  36. exports.createECDH = require('create-ecdh')
  37. var publicEncrypt = require('public-encrypt')
  38. exports.publicEncrypt = publicEncrypt.publicEncrypt
  39. exports.privateEncrypt = publicEncrypt.privateEncrypt
  40. exports.publicDecrypt = publicEncrypt.publicDecrypt
  41. exports.privateDecrypt = publicEncrypt.privateDecrypt
  42. // the least I can do is make error messages for the rest of the node.js/crypto api.
  43. // ;[
  44. // 'createCredentials'
  45. // ].forEach(function (name) {
  46. // exports[name] = function () {
  47. // throw new Error([
  48. // 'sorry, ' + name + ' is not implemented yet',
  49. // 'we accept pull requests',
  50. // 'https://github.com/crypto-browserify/crypto-browserify'
  51. // ].join('\n'))
  52. // }
  53. // })
  54. var rf = require('randomfill')
  55. exports.randomFill = rf.randomFill
  56. exports.randomFillSync = rf.randomFillSync
  57. exports.createCredentials = function () {
  58. throw new Error([
  59. 'sorry, createCredentials is not implemented yet',
  60. 'we accept pull requests',
  61. 'https://github.com/crypto-browserify/crypto-browserify'
  62. ].join('\n'))
  63. }
  64. exports.constants = {
  65. 'DH_CHECK_P_NOT_SAFE_PRIME': 2,
  66. 'DH_CHECK_P_NOT_PRIME': 1,
  67. 'DH_UNABLE_TO_CHECK_GENERATOR': 4,
  68. 'DH_NOT_SUITABLE_GENERATOR': 8,
  69. 'NPN_ENABLED': 1,
  70. 'ALPN_ENABLED': 1,
  71. 'RSA_PKCS1_PADDING': 1,
  72. 'RSA_SSLV23_PADDING': 2,
  73. 'RSA_NO_PADDING': 3,
  74. 'RSA_PKCS1_OAEP_PADDING': 4,
  75. 'RSA_X931_PADDING': 5,
  76. 'RSA_PKCS1_PSS_PADDING': 6,
  77. 'POINT_CONVERSION_COMPRESSED': 2,
  78. 'POINT_CONVERSION_UNCOMPRESSED': 4,
  79. 'POINT_CONVERSION_HYBRID': 6
  80. }