no-style-please2-plugins 0.7.4 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f70756daa935247238f2e2b403c75554db41b447acbaa0339be4e882478bb20
4
- data.tar.gz: ab75d02a6103b328403d6b65bebafcfc564345f1f2341476e3e89a83a0a49c15
3
+ metadata.gz: 1481f05da7257deb43b4f2d8475d8e708e4bb3d4c31f23ca3f20580ee6ac60cf
4
+ data.tar.gz: df0238ad5567dc1ce3bb8e242b2258accf3ff65f752c007522dd1dea22f0f75f
5
5
  SHA512:
6
- metadata.gz: 6ec817b045439f0512850cc77c0a418d785d0f0ed2fbe9f9c5d28b4fbda203fabd997a287a70ceb5be3ff91893348984170d8a6dd760ee369d9f7c744605c575
7
- data.tar.gz: a8acf8fd6d2176818d420e8f7f41c8e349215da10696ab5af751b3cbd126562bd1655174a5d2c128a35b394d6c9998034a5a9bf6dfd19d04c6cc6b3ade645d0f
6
+ metadata.gz: 3a655d2b12c8c5ccfaedeeebb186b5c41438861c293d2fa3a89dd173e72f6945cf2af2767e8a3be4df5b0cd4ca9ed221559b6c046b7a9720a3bfdf1925b752f6
7
+ data.tar.gz: cec5db851784412d946b307f55fb374efdaade832752d96dff3027c59298989f9cf0e1e27a1a9e7c0b8130038511669cd09d8abfc98f849e85eec87ec8ac5154
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- no-style-please2-plugins (0.7.4)
4
+ no-style-please2-plugins (0.9.0)
5
5
  digest
6
6
  jekyll (~> 4.0)
7
7
  ltec (~> 0.1.2)
data/README.md CHANGED
@@ -21,7 +21,7 @@ If bundler is not being used to manage dependencies, install the gem by executin
21
21
 
22
22
  ## Usage
23
23
 
24
- see this [demo](https://vitock.ink/no-style-please-demo/)
24
+ see this [demo](https://vitock.github.io/no-style-please/)
25
25
 
26
26
  ## Development
27
27
 
data/lib/enc.rb CHANGED
@@ -5,9 +5,46 @@ require 'ltec'
5
5
  require "jekyll"
6
6
  require "fileutils"
7
7
  module Jekyll
8
- def test
9
- end
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 'E1.' + Base64.strict_encode64(iv + encrypted + cipher.auth_tag)
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
- end
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
- Liquid::Template.register_filter(Jekyll::EncFilter)
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
- def bin2hex(str)
135
- str.unpack('C*').map{ |b| "%02x" % b }.join('')
136
- end
213
+
214
+ end
215
+
216
+
217
+ Liquid::Template.register_filter(Jekyll::EncFilter)
137
218
 
138
- def hex2bin(str)
139
- [str].pack "H*"
219
+ class Test
220
+ extend EncFilter
140
221
  end
141
222
 
142
223
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoStylePlease2
4
- VERSION = "0.7.4"
4
+ VERSION = "0.9.0"
5
5
  end
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
- puts $Key
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.7.4
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: 2024-12-31 00:00:00.000000000 Z
11
+ date: 2025-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll