W3cubDocs

/Ruby 3

class Net::IMAP::CramMD5Authenticator

Parent:
Object

Authenticator for the “CRAM-MD5” authentication type. See authenticate().

Public Class Methods

new(user, password) Show source
# File lib/net/imap.rb, line 3554
def initialize(user, password)
  @user = user
  @password = password
end

Public Instance Methods

process(challenge) Show source
# File lib/net/imap.rb, line 3547
def process(challenge)
  digest = hmac_md5(challenge, @password)
  return @user + " " + digest
end

Private Instance Methods

hmac_md5(text, key) Show source
# File lib/net/imap.rb, line 3559
def hmac_md5(text, key)
  if key.length > 64
    key = Digest::MD5.digest(key)
  end

  k_ipad = key + "\0" * (64 - key.length)
  k_opad = key + "\0" * (64 - key.length)
  for i in 0..63
    k_ipad[i] = (k_ipad[i].ord ^ 0x36).chr
    k_opad[i] = (k_opad[i].ord ^ 0x5c).chr
  end

  digest = Digest::MD5.digest(k_ipad + text)

  return Digest::MD5.hexdigest(k_opad + digest)
end

Ruby Core © 1993–2020 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.