huami 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +8 -0
- data/bin/huami +13 -0
- data/lib/huami.rb +50 -0
- metadata +48 -0
data/Rakefile
ADDED
data/bin/huami
ADDED
data/lib/huami.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'highline/import'
|
3
|
+
require 'openssl'
|
4
|
+
|
5
|
+
class Huami
|
6
|
+
|
7
|
+
STR1 = "snow"
|
8
|
+
STR2 = "kise"
|
9
|
+
STR3 = "sunlovesnow1990090127xykab"
|
10
|
+
|
11
|
+
def self.huami(key, password)
|
12
|
+
md5one = md5_hmac(key, password)
|
13
|
+
md5two = md5_hmac(STR1, md5one)
|
14
|
+
md5three = md5_hmac(STR2, md5one)
|
15
|
+
|
16
|
+
# 转换大小写
|
17
|
+
rule = md5three.split('')
|
18
|
+
source = md5two.split('')
|
19
|
+
for i in (0..31)
|
20
|
+
if STR3.include? rule[i]
|
21
|
+
source[i] = source[i].upcase
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# 保证首字符为字母
|
26
|
+
if is_digit(source[0])
|
27
|
+
code16 = "K" + source[1..15].join()
|
28
|
+
else
|
29
|
+
code16 = source[0..15].join()
|
30
|
+
end
|
31
|
+
|
32
|
+
return code16
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.md5_hmac(key, password)
|
36
|
+
digest = OpenSSL::Digest::Digest.new('md5')
|
37
|
+
return OpenSSL::HMAC.hexdigest(digest, key, password)
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.is_digit(string)
|
41
|
+
return string.strip =~ /^[0-9]$/
|
42
|
+
end
|
43
|
+
|
44
|
+
def self.usage
|
45
|
+
puts "Usage:"
|
46
|
+
puts "huami.rb KEY"
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: huami
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Wei Zhu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-01-31 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Management of password in rememberable way.
|
15
|
+
email: yesmeck@gmail.com
|
16
|
+
executables:
|
17
|
+
- huami
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- Rakefile
|
22
|
+
- lib/huami.rb
|
23
|
+
- bin/huami
|
24
|
+
homepage: http://yesmeck.com
|
25
|
+
licenses: []
|
26
|
+
post_install_message:
|
27
|
+
rdoc_options: []
|
28
|
+
require_paths:
|
29
|
+
- lib
|
30
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
31
|
+
none: false
|
32
|
+
requirements:
|
33
|
+
- - ! '>='
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '0'
|
36
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 1.8.12
|
45
|
+
signing_key:
|
46
|
+
specification_version: 3
|
47
|
+
summary: Huami
|
48
|
+
test_files: []
|