no-style-please2-plugins 0.7.4 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/lib/enc.rb +92 -11
- data/lib/version/version.rb +1 -1
- data/test.rb +13 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1481f05da7257deb43b4f2d8475d8e708e4bb3d4c31f23ca3f20580ee6ac60cf
|
4
|
+
data.tar.gz: df0238ad5567dc1ce3bb8e242b2258accf3ff65f752c007522dd1dea22f0f75f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3a655d2b12c8c5ccfaedeeebb186b5c41438861c293d2fa3a89dd173e72f6945cf2af2767e8a3be4df5b0cd4ca9ed221559b6c046b7a9720a3bfdf1925b752f6
|
7
|
+
data.tar.gz: cec5db851784412d946b307f55fb374efdaade832752d96dff3027c59298989f9cf0e1e27a1a9e7c0b8130038511669cd09d8abfc98f849e85eec87ec8ac5154
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/enc.rb
CHANGED
@@ -5,9 +5,46 @@ require 'ltec'
|
|
5
5
|
require "jekyll"
|
6
6
|
require "fileutils"
|
7
7
|
module Jekyll
|
8
|
-
|
9
|
-
|
8
|
+
|
9
|
+
|
10
|
+
|
10
11
|
class EncFilterTool
|
12
|
+
def EncFilterTool.getAllKey(page)
|
13
|
+
site = Jekyll::sites[0]
|
14
|
+
keys = []
|
15
|
+
key = "#{page['key']}"
|
16
|
+
if key != nil && key.length > 0
|
17
|
+
keys << key
|
18
|
+
end
|
19
|
+
|
20
|
+
posttags = page["tags"]
|
21
|
+
enctags = site.config['enc_tags']
|
22
|
+
if posttags && posttags.length > 0 && enctags
|
23
|
+
|
24
|
+
for tag in posttags
|
25
|
+
for enctag in enctags
|
26
|
+
if enctag['tag'] == tag
|
27
|
+
key = "#{enctag['password']}"
|
28
|
+
keys << key
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
keys.map do |key|
|
34
|
+
if key.length > 50
|
35
|
+
pubkey = ENV["JEKYLL_EC_PRIVATEKEY"]
|
36
|
+
if pubkey == nil
|
37
|
+
raise 'JEKYLL_EC_PRIVATEKEY not set on envionment'
|
38
|
+
end
|
39
|
+
key = Ltec::EC.decrypt(pubkey,key)
|
40
|
+
|
41
|
+
if key == nil || key.length == 0
|
42
|
+
raise "key decription fail"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
key
|
46
|
+
end
|
47
|
+
end
|
11
48
|
def EncFilterTool.getKey(content,page)
|
12
49
|
site = Jekyll::sites[0]
|
13
50
|
key = "#{page['key']}"
|
@@ -57,9 +94,22 @@ module Jekyll
|
|
57
94
|
return "#{key}"
|
58
95
|
end
|
59
96
|
end
|
97
|
+
# 大端模式
|
98
|
+
def self.nmberToBinary4(num)
|
99
|
+
[num].pack("N")[0, 4]
|
100
|
+
end
|
101
|
+
|
60
102
|
module EncFilter
|
61
103
|
|
104
|
+
|
62
105
|
$KeyMap = {}
|
106
|
+
def bin2hex(str)
|
107
|
+
str.unpack('C*').map{ |b| "%02x" % b }.join('')
|
108
|
+
end
|
109
|
+
|
110
|
+
def self.hex2bin(str)
|
111
|
+
[str].pack "H*"
|
112
|
+
end
|
63
113
|
def genKey(password)
|
64
114
|
cacheKey = $KeyMap[password]
|
65
115
|
if cacheKey
|
@@ -80,7 +130,7 @@ module Jekyll
|
|
80
130
|
cipher.iv = iv
|
81
131
|
cipher.key = genKey password
|
82
132
|
encrypted = cipher.update(msg) + cipher.final
|
83
|
-
return '
|
133
|
+
return 'E2.' + Base64.strict_encode64(iv + encrypted + cipher.auth_tag)
|
84
134
|
|
85
135
|
end
|
86
136
|
def get_encrypt_id(content,page)
|
@@ -92,7 +142,6 @@ module Jekyll
|
|
92
142
|
return ""
|
93
143
|
end
|
94
144
|
end
|
95
|
-
|
96
145
|
def encrypt_content(content,page,prefix)
|
97
146
|
psw = EncFilterTool.getKey(content,page)
|
98
147
|
psw = prefix + psw + prefix
|
@@ -123,20 +172,52 @@ module Jekyll
|
|
123
172
|
return ''
|
124
173
|
end
|
125
174
|
|
175
|
+
def rand_bytes(_,n2)
|
176
|
+
return bin2hex(OpenSSL::Random.random_bytes(n2))
|
177
|
+
end
|
178
|
+
|
126
179
|
|
127
|
-
|
180
|
+
def encrypt_content_v2(content,pswHex)
|
181
|
+
if !pswHex || pswHex.length != 64
|
182
|
+
raise "invalid Key:" + pswHex
|
183
|
+
end
|
184
|
+
cipher = OpenSSL::Cipher::AES.new(256, :CTR).encrypt
|
185
|
+
iv = cipher.random_iv
|
186
|
+
cipher.iv = iv
|
187
|
+
cipher.key = EncFilter.hex2bin(pswHex)
|
188
|
+
encrypted = cipher.update(content) + cipher.final
|
128
189
|
|
190
|
+
|
191
|
+
len = 4 + iv.length + encrypted.length
|
192
|
+
lenBf = Jekyll.nmberToBinary4(len)
|
193
|
+
lenBf2 = lenBf.bytes.map.each_with_index do |v,i|
|
194
|
+
z = i ^ iv.bytes[i ]
|
195
|
+
v ^ z
|
196
|
+
end.pack('C*')
|
197
|
+
return Base64.strict_encode64(lenBf2 + iv + encrypted )
|
198
|
+
end
|
129
199
|
|
130
|
-
|
200
|
+
def encrypt_key(x,page,keyHex2Enc,encid)
|
201
|
+
arr = EncFilterTool.getAllKey(page)
|
202
|
+
newArr = arr.map do |k|
|
203
|
+
key = genKey encid + k + encid
|
204
|
+
hexKey = bin2hex key
|
205
|
+
Base64.strict_decode64(encrypt_content_v2(EncFilter.hex2bin(keyHex2Enc),hexKey))
|
206
|
+
end
|
131
207
|
|
208
|
+
Base64.strict_encode64(newArr.join)
|
132
209
|
|
210
|
+
end
|
211
|
+
|
133
212
|
|
134
|
-
|
135
|
-
|
136
|
-
|
213
|
+
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
Liquid::Template.register_filter(Jekyll::EncFilter)
|
137
218
|
|
138
|
-
|
139
|
-
|
219
|
+
class Test
|
220
|
+
extend EncFilter
|
140
221
|
end
|
141
222
|
|
142
223
|
|
data/lib/version/version.rb
CHANGED
data/test.rb
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'openssl'
|
4
4
|
require 'base64'
|
5
|
+
require_relative "lib/enc"
|
5
6
|
$Key = {}
|
6
7
|
def genKey(password)
|
7
8
|
cache = $Key[password]
|
@@ -51,6 +52,8 @@ def decrypt(enstring,password)
|
|
51
52
|
end
|
52
53
|
|
53
54
|
|
55
|
+
|
56
|
+
|
54
57
|
msg = '我的 12a23007'
|
55
58
|
z = encrypt msg,'123'
|
56
59
|
puts z
|
@@ -64,4 +67,13 @@ genKey '123'
|
|
64
67
|
genKey '123'
|
65
68
|
genKey '123'
|
66
69
|
genKey '456'
|
67
|
-
|
70
|
+
|
71
|
+
puts '---'
|
72
|
+
a = Jekyll::nmberToBinary4(256)
|
73
|
+
puts a.unpack1('H*')
|
74
|
+
a = a.bytes.map.each_with_index do |byte,i | byte ^ i
|
75
|
+
end.pack('C*')
|
76
|
+
|
77
|
+
puts a.unpack1('H*')
|
78
|
+
|
79
|
+
puts Jekyll::Test.encrypt_content_v2('333333a','00000000000000052f5c9b07ebc4464717978b174c440573df03e2962d98946c')
|
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.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- vitock
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: jekyll
|