Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

pbkdf2.tests.js 5.0 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. var assert = require("assert");
  2. var pbkdf2 = require("../src/pbkdf2");
  3. describe("pbkdf2", function() {
  4. it("secret, salt, 2 iterations, 32 keylen, sha256 hash", function() {
  5. return pbkdf2("secret", "salt", 2, 32, "sha256").then(function(key) {
  6. assert.equal(
  7. "f92f45f9df4c2aeabae1ed3c16f7b64660c1f8e377fa9b4699b23c2c3a29f569",
  8. key
  9. );
  10. });
  11. });
  12. it("use pbkdf2 with 8192 iterations and sha256", function() {
  13. return pbkdf2(
  14. "password",
  15. "test@example.org",
  16. 8192,
  17. 32,
  18. "sha256"
  19. ).then(function(key) {
  20. assert.equal(
  21. "d8af5f918db6b65b1db3d3984e5a400e39e1dbb19462220e4431de283809f472",
  22. key
  23. );
  24. });
  25. });
  26. it("customize number of iterations", function() {
  27. return pbkdf2(
  28. "password",
  29. "test@example.org",
  30. 4096,
  31. 32,
  32. "sha256"
  33. ).then(function(key) {
  34. assert.equal(
  35. "0a91208545e3aa4935d3a22984ca097a7669259a04d261ac16361bdc1a2e960f",
  36. key
  37. );
  38. });
  39. });
  40. it("customize key length", function() {
  41. return pbkdf2(
  42. "password",
  43. "test@example.org",
  44. 8192,
  45. 16,
  46. "sha256"
  47. ).then(function(key) {
  48. assert.equal("d8af5f918db6b65b1db3d3984e5a400e", key);
  49. });
  50. });
  51. it("customize iterations and key length", function() {
  52. return pbkdf2(
  53. "password",
  54. "test@example.org",
  55. 4096,
  56. 16,
  57. "sha256"
  58. ).then(function(key) {
  59. assert.equal("0a91208545e3aa4935d3a22984ca097a", key);
  60. });
  61. });
  62. it("utf8 parameter", function() {
  63. return pbkdf2(
  64. "♥ LessPass ♥",
  65. "test@example.org",
  66. 8192,
  67. 32,
  68. "sha256"
  69. ).then(function(key) {
  70. assert.equal(
  71. "997fe81d3d0db236e039c75efdb487f17a902fdf94f9dacaa9884329c85d9651",
  72. key
  73. );
  74. });
  75. });
  76. it("auto generated test 0", function() {
  77. return pbkdf2(
  78. "password",
  79. "contact@lesspass.com",
  80. 8192,
  81. 32,
  82. "sha256"
  83. ).then(function(key) {
  84. assert.equal(
  85. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  86. key
  87. );
  88. });
  89. });
  90. it("auto generated test 1", function() {
  91. return pbkdf2(
  92. "password",
  93. "contact@lesspass.com",
  94. 8192,
  95. 32,
  96. "sha256"
  97. ).then(function(key) {
  98. assert.equal(
  99. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  100. key
  101. );
  102. });
  103. });
  104. it("auto generated test 2", function() {
  105. return pbkdf2(
  106. "password",
  107. "contact@lesspass.com",
  108. 8192,
  109. 32,
  110. "sha256"
  111. ).then(function(key) {
  112. assert.equal(
  113. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  114. key
  115. );
  116. });
  117. });
  118. it("auto generated test 3", function() {
  119. return pbkdf2(
  120. "password",
  121. "contact@lesspass.com",
  122. 8192,
  123. 32,
  124. "sha256"
  125. ).then(function(key) {
  126. assert.equal(
  127. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  128. key
  129. );
  130. });
  131. });
  132. it("auto generated test 4", function() {
  133. return pbkdf2(
  134. "password",
  135. "contact@lesspass.com",
  136. 8192,
  137. 32,
  138. "sha256"
  139. ).then(function(key) {
  140. assert.equal(
  141. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  142. key
  143. );
  144. });
  145. });
  146. it("auto generated test 5", function() {
  147. return pbkdf2(
  148. "password",
  149. "contact@lesspass.com",
  150. 8192,
  151. 32,
  152. "sha256"
  153. ).then(function(key) {
  154. assert.equal(
  155. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  156. key
  157. );
  158. });
  159. });
  160. it("auto generated test 6", function() {
  161. return pbkdf2(
  162. "password",
  163. "contact@lesspass.com",
  164. 8192,
  165. 32,
  166. "sha256"
  167. ).then(function(key) {
  168. assert.equal(
  169. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  170. key
  171. );
  172. });
  173. });
  174. it("auto generated test 7", function() {
  175. return pbkdf2(
  176. "password",
  177. "contact@lesspass.com",
  178. 8192,
  179. 32,
  180. "sha256"
  181. ).then(function(key) {
  182. assert.equal(
  183. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  184. key
  185. );
  186. });
  187. });
  188. it("auto generated test 8", function() {
  189. return pbkdf2(
  190. "password",
  191. "contact@lesspass.com",
  192. 8192,
  193. 32,
  194. "sha256"
  195. ).then(function(key) {
  196. assert.equal(
  197. "63d850713d0b2f7f2c4396fe93f4ac0c6bc7485f9e7473c4b8c4a33ec12199c0",
  198. key
  199. );
  200. });
  201. });
  202. it("auto generated test 9", function() {
  203. return pbkdf2("password", "lesspass", 8192, 32, "sha256").then(function(
  204. key
  205. ) {
  206. assert.equal(
  207. "7d05ee25597dcc3ac16d082aa910e7707f75be620ed8db5bef7245e2a8579116",
  208. key
  209. );
  210. });
  211. });
  212. it("auto generated test 10", function() {
  213. return pbkdf2(
  214. "password2",
  215. "contact@lesspass.com",
  216. 8192,
  217. 32,
  218. "sha256"
  219. ).then(function(key) {
  220. assert.equal(
  221. "ce853092fc54fe88c281e38df97bd5826d64e6bee315dc94939cbba8930df0e4",
  222. key
  223. );
  224. });
  225. });
  226. });