no-style-please2-plugins 0.4.3 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/gem.gemspec +1 -1
- data/lib/enc.rb +28 -10
- data/lib/version/version.rb +1 -1
- data/test.rb +66 -17
- metadata +2 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 59d293c063433293db2fed307b79dcb273375902063bf528a3abd8264fbc926c
|
4
|
+
data.tar.gz: f24ca36b1f368811a257411184cd26837e7ed0126128859c3f64be663cebfcb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e83ac543cf0985152d69e143a3dce55626c54588620c076b2435f7e9be321b49f86af338f1968fc02283cfac75ffc6bb3b2ea3783860cc6a9e25ca0032d89e68
|
7
|
+
data.tar.gz: 8b6ba41e812b9e6b2d318606968c8cfbc549eb1fbcc890c9dd61a2a8a77ab9de374d5ccfd9bc68272843cfb60f5d1dcbc7f4ad56b31ff69d3b942ae976e99b2c
|
data/gem.gemspec
CHANGED
@@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
|
|
34
34
|
|
35
35
|
spec.add_dependency "jekyll", "~>4.0"
|
36
36
|
spec.add_dependency "ltec", "~> 0.1.2"
|
37
|
-
spec.add_dependency "salsa20", "~> 0.1.3"
|
37
|
+
# spec.add_dependency "salsa20", "~> 0.1.3"
|
38
38
|
spec.add_dependency "digest"
|
39
39
|
# Uncomment to register a new dependency of your gem
|
40
40
|
# spec.add_dependency "example-gem", "~> 1.0"
|
data/lib/enc.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require 'openssl'
|
2
2
|
require 'base64'
|
3
|
-
require 'salsa20'
|
4
3
|
require 'digest'
|
5
4
|
require 'ltec'
|
6
5
|
require "jekyll"
|
@@ -58,6 +57,31 @@ module Jekyll
|
|
58
57
|
end
|
59
58
|
end
|
60
59
|
module EncFilter
|
60
|
+
|
61
|
+
$KeyMap = {}
|
62
|
+
def genKey(password)
|
63
|
+
cacheKey = $KeyMap[password]
|
64
|
+
if cacheKey
|
65
|
+
return cacheKey
|
66
|
+
end
|
67
|
+
salt = 'this is a salt string 20221019'
|
68
|
+
iter = 12345
|
69
|
+
key_len = 32
|
70
|
+
key = OpenSSL::KDF.pbkdf2_hmac(password, salt: salt, iterations: iter,
|
71
|
+
length: key_len, hash: "sha256")
|
72
|
+
$KeyMap[password] = key
|
73
|
+
return key
|
74
|
+
end
|
75
|
+
|
76
|
+
def encrypt(msg,password)
|
77
|
+
cipher = OpenSSL::Cipher::AES.new(256, :GCM).encrypt
|
78
|
+
iv = cipher.random_iv
|
79
|
+
cipher.iv = iv
|
80
|
+
cipher.key = genKey password
|
81
|
+
encrypted = cipher.update(msg) + cipher.final
|
82
|
+
return 'E1.' + Base64.strict_encode64(iv + encrypted + cipher.auth_tag)
|
83
|
+
|
84
|
+
end
|
61
85
|
def get_encrypt_id(content,page)
|
62
86
|
key = EncFilterTool.getKey(content,page)
|
63
87
|
if key != nil && key.length > 0
|
@@ -68,15 +92,9 @@ module Jekyll
|
|
68
92
|
end
|
69
93
|
|
70
94
|
def encrypt_content(content,page,prefix)
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
iv = Digest::MD5.hexdigest(content).downcase()
|
75
|
-
ivHex = iv[0...16]
|
76
|
-
iv = ivHex.scan(/../).map { |x| x.hex.chr }.join
|
77
|
-
encryptor = Salsa20.new(key, iv)
|
78
|
-
encrypted_text = encryptor.encrypt(content)
|
79
|
-
return ivHex + ":" + Base64.strict_encode64(encrypted_text)
|
95
|
+
psw = EncFilterTool.getKey(content,page)
|
96
|
+
psw = prefix + psw + prefix
|
97
|
+
return encrypt content,psw
|
80
98
|
end
|
81
99
|
|
82
100
|
|
data/lib/version/version.rb
CHANGED
data/test.rb
CHANGED
@@ -1,18 +1,67 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
2
|
+
|
3
|
+
require 'openssl'
|
4
|
+
require 'base64'
|
5
|
+
$Key = {}
|
6
|
+
def genKey(password)
|
7
|
+
cache = $Key[password]
|
8
|
+
if cache
|
9
|
+
puts "cache",cache
|
10
|
+
return cache
|
11
|
+
end
|
12
|
+
salt = 'this is a salt string 20221019'
|
13
|
+
iter = 12345
|
14
|
+
key_len = 32
|
15
|
+
key = OpenSSL::KDF.pbkdf2_hmac(password, salt: salt, iterations: iter,
|
16
|
+
length: key_len, hash: "sha256")
|
17
|
+
$Key[password] = key
|
18
|
+
return key
|
19
|
+
end
|
20
|
+
|
21
|
+
def encrypt(msg,password)
|
22
|
+
|
23
|
+
cipher = OpenSSL::Cipher::AES.new(256, :GCM).encrypt
|
24
|
+
iv = cipher.random_iv
|
25
|
+
cipher.iv = iv
|
26
|
+
cipher.key = genKey password
|
27
|
+
encrypted = cipher.update(msg) + cipher.final
|
28
|
+
return 'E1.' + Base64.strict_encode64(iv + encrypted + cipher.auth_tag)
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
def decrypt(enstring,password)
|
34
|
+
b64 = enstring[3..-1]
|
35
|
+
data = Base64.strict_decode64 b64
|
36
|
+
|
37
|
+
len = data.bytesize
|
38
|
+
iv = data[0...12]
|
39
|
+
auth_tag = data[0...16] #data[len-16..-1]
|
40
|
+
encdata = data[12...len-16]
|
41
|
+
|
42
|
+
|
43
|
+
cipher = OpenSSL::Cipher::AES.new(256, :GCM).decrypt
|
44
|
+
cipher.iv = iv
|
45
|
+
cipher.key = genKey password
|
46
|
+
# cipher.auth_tag = '1234567890123456'
|
47
|
+
|
48
|
+
result = cipher.update(encdata)
|
49
|
+
return result
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
msg = '我的 12a23007'
|
55
|
+
z = encrypt msg,'123'
|
56
|
+
puts z
|
57
|
+
|
58
|
+
puts z[3..-1]
|
59
|
+
|
60
|
+
m = decrypt z ,'123'
|
61
|
+
puts m
|
62
|
+
|
63
|
+
genKey '123'
|
64
|
+
genKey '123'
|
65
|
+
genKey '123'
|
66
|
+
genKey '456'
|
67
|
+
puts $Key
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: no-style-please2-plugins
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vitock
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-10-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.1.2
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: salsa20
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.1.3
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.1.3
|
55
41
|
- !ruby/object:Gem::Dependency
|
56
42
|
name: digest
|
57
43
|
requirement: !ruby/object:Gem::Requirement
|