完成签约之后直接添加人员,录入下发凭证
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
5.1 KiB

  1. // Licensed under the Apache License, Version 2.0 (the "License");
  2. // you may not use this file except in compliance with the License.
  3. // You may obtain a copy of the License at
  4. //
  5. // http://www.apache.org/licenses/LICENSE-2.0
  6. //
  7. // Unless required by applicable law or agreed to in writing, software
  8. // distributed under the License is distributed on an "AS IS" BASIS,
  9. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. // See the License for the specific language governing permissions and
  11. // limitations under the License.
  12. // Copyright 2005 Google Inc. All Rights Reserved.
  13. /**
  14. * @fileoverview SHA-1 cryptographic hash.
  15. * Variable names follow the notation in FIPS PUB 180-3:
  16. * http://csrc.nist.gov/publications/fips/fips180-3/fips180-3_final.pdf.
  17. *
  18. * Usage:
  19. * var sha1 = new goog.crypt.sha1();
  20. * sha1.update(bytes);
  21. * var hash = sha1.digest();
  22. *
  23. */
  24. /**
  25. * SHA-1 cryptographic hash constructor.
  26. *
  27. * The properties declared here are discussed in the above algorithm document.
  28. * @constructor
  29. */
  30. var Sha1 = function() {
  31. /**
  32. * Holds the previous values of accumulated variables a-e in the compress_
  33. * function.
  34. * @type {Array.<number>}
  35. * @private
  36. */
  37. this.chain_ = [];
  38. /**
  39. * A buffer holding the partially computed hash result.
  40. * @type {Array.<number>}
  41. * @private
  42. */
  43. this.buf_ = [];
  44. /**
  45. * An array of 80 bytes, each a part of the message to be hashed. Referred to
  46. * as the message schedule in the docs.
  47. * @type {Array.<number>}
  48. * @private
  49. */
  50. this.W_ = [];
  51. /**
  52. * Contains data needed to pad messages less than 64 bytes.
  53. * @type {Array.<number>}
  54. * @private
  55. */
  56. this.pad_ = [];
  57. this.pad_[0] = 128;
  58. for (var i = 1; i < 64; ++i) {
  59. this.pad_[i] = 0;
  60. }
  61. this.reset();
  62. };
  63. /**
  64. * Resets the internal accumulator.
  65. */
  66. Sha1.prototype.reset = function() {
  67. this.chain_[0] = 0x67452301;
  68. this.chain_[1] = 0xefcdab89;
  69. this.chain_[2] = 0x98badcfe;
  70. this.chain_[3] = 0x10325476;
  71. this.chain_[4] = 0xc3d2e1f0;
  72. this.inbuf_ = 0;
  73. this.total_ = 0;
  74. };
  75. /**
  76. * Internal helper performing 32 bit left rotate.
  77. * @return {number} w rotated left by r bits.
  78. * @private
  79. */
  80. Sha1.prototype.rotl_ = function(w, r) {
  81. return ((w << r) | (w >>> (32 - r))) & 0xffffffff;
  82. };
  83. /**
  84. * Internal compress helper function.
  85. * @param {Array} buf containing block to compress.
  86. * @private
  87. */
  88. Sha1.prototype.compress_ = function(buf) {
  89. var W = this.W_;
  90. // get 16 big endian words
  91. for (var i = 0; i < 64; i += 4) {
  92. var w = (buf[i] << 24) |
  93. (buf[i + 1] << 16) |
  94. (buf[i + 2] << 8) |
  95. (buf[i + 3]);
  96. W[i / 4] = w;
  97. }
  98. // expand to 80 words
  99. for (var i = 16; i < 80; i++) {
  100. W[i] = this.rotl_(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
  101. }
  102. var a = this.chain_[0];
  103. var b = this.chain_[1];
  104. var c = this.chain_[2];
  105. var d = this.chain_[3];
  106. var e = this.chain_[4];
  107. var f, k;
  108. for (var i = 0; i < 80; i++) {
  109. if (i < 40) {
  110. if (i < 20) {
  111. f = d ^ (b & (c ^ d));
  112. k = 0x5a827999;
  113. } else {
  114. f = b ^ c ^ d;
  115. k = 0x6ed9eba1;
  116. }
  117. } else {
  118. if (i < 60) {
  119. f = (b & c) | (d & (b | c));
  120. k = 0x8f1bbcdc;
  121. } else {
  122. f = b ^ c ^ d;
  123. k = 0xca62c1d6;
  124. }
  125. }
  126. var t = (this.rotl_(a, 5) + f + e + k + W[i]) & 0xffffffff;
  127. e = d;
  128. d = c;
  129. c = this.rotl_(b, 30);
  130. b = a;
  131. a = t;
  132. }
  133. this.chain_[0] = (this.chain_[0] + a) & 0xffffffff;
  134. this.chain_[1] = (this.chain_[1] + b) & 0xffffffff;
  135. this.chain_[2] = (this.chain_[2] + c) & 0xffffffff;
  136. this.chain_[3] = (this.chain_[3] + d) & 0xffffffff;
  137. this.chain_[4] = (this.chain_[4] + e) & 0xffffffff;
  138. };
  139. /**
  140. * Adds a byte array to internal accumulator.
  141. * @param {Array.<number>} bytes to add to digest.
  142. * @param {number} opt_length is # of bytes to compress.
  143. */
  144. Sha1.prototype.update = function(bytes, opt_length) {
  145. if (!opt_length) {
  146. opt_length = bytes.length;
  147. }
  148. var n = 0;
  149. // Optimize for 64 byte chunks at 64 byte boundaries.
  150. if (this.inbuf_ == 0) {
  151. while (n + 64 < opt_length) {
  152. this.compress_(bytes.slice(n, n + 64));
  153. n += 64;
  154. this.total_ += 64;
  155. }
  156. }
  157. while (n < opt_length) {
  158. this.buf_[this.inbuf_++] = bytes[n++];
  159. this.total_++;
  160. if (this.inbuf_ == 64) {
  161. this.inbuf_ = 0;
  162. this.compress_(this.buf_);
  163. // Pick up 64 byte chunks.
  164. while (n + 64 < opt_length) {
  165. this.compress_(bytes.slice(n, n + 64));
  166. n += 64;
  167. this.total_ += 64;
  168. }
  169. }
  170. }
  171. };
  172. /**
  173. * @return {Array} byte[20] containing finalized hash.
  174. */
  175. Sha1.prototype.digest = function() {
  176. var digest = [];
  177. var totalBits = this.total_ * 8;
  178. // Add pad 0x80 0x00*.
  179. if (this.inbuf_ < 56) {
  180. this.update(this.pad_, 56 - this.inbuf_);
  181. } else {
  182. this.update(this.pad_, 64 - (this.inbuf_ - 56));
  183. }
  184. // Add # bits.
  185. for (var i = 63; i >= 56; i--) {
  186. this.buf_[i] = totalBits & 255;
  187. totalBits >>>= 8;
  188. }
  189. this.compress_(this.buf_);
  190. var n = 0;
  191. for (var i = 0; i < 5; i++) {
  192. for (var j = 24; j >= 0; j -= 8) {
  193. digest[n++] = (this.chain_[i] >> j) & 255;
  194. }
  195. }
  196. return digest;
  197. };