Method: QyWechat::PKCS7Encoder#encode

Defined in:
lib/qy_wechat/helpers/pkcs7_encoder.rb

#encode(text) ⇒ Object

对需要加密的明文进行填充补位返回补齐明文字符串



18
19
20
21
22
23
24
25
# File 'lib/qy_wechat/helpers/pkcs7_encoder.rb', line 18

def encode(text)
  # 计算需要填充的位数
  amount_to_pad = BLOCK_SIZE - (text.length % BLOCK_SIZE)
  amount_to_pad = BLOCK_SIZE if amount_to_pad == 0
  # 获得补位所用的字符
  pad_chr = amount_to_pad.chr
  "#{text}#{pad_chr * amount_to_pad}"
end