no-style-please2-plugins 0.7.4 → 0.8.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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -1
  3. data/lib/enc.rb +77 -12
  4. data/lib/version/version.rb +1 -1
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3f70756daa935247238f2e2b403c75554db41b447acbaa0339be4e882478bb20
4
- data.tar.gz: ab75d02a6103b328403d6b65bebafcfc564345f1f2341476e3e89a83a0a49c15
3
+ metadata.gz: eb824516aa69202aeb751b710764aea4f7c8e352bfcf94fe7ee426c66f354a45
4
+ data.tar.gz: dd951357fe4e823aa00456d13814ae8815fbf40026318b0e132554564a28dbfd
5
5
  SHA512:
6
- metadata.gz: 6ec817b045439f0512850cc77c0a418d785d0f0ed2fbe9f9c5d28b4fbda203fabd997a287a70ceb5be3ff91893348984170d8a6dd760ee369d9f7c744605c575
7
- data.tar.gz: a8acf8fd6d2176818d420e8f7f41c8e349215da10696ab5af751b3cbd126562bd1655174a5d2c128a35b394d6c9998034a5a9bf6dfd19d04c6cc6b3ade645d0f
6
+ metadata.gz: d5ffba3bbbe75ba9dcfb62e15d01ce34ac76ec3d3dcdd554f4244dc93093575c4fbb93e3a67859b00e2ceee476baff27d911fefdf4aedff851d63042287cf3e2
7
+ data.tar.gz: 58266e9e6dfd9767022640fdc5bad66a5876537e4dcb49c744fff3a09180fba54b02d71a4807841d747f761b75166097da4b83437c19da9fb529592464ca22f3
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']}"
@@ -59,7 +96,15 @@ module Jekyll
59
96
  end
60
97
  module EncFilter
61
98
 
99
+
62
100
  $KeyMap = {}
101
+ def bin2hex(str)
102
+ str.unpack('C*').map{ |b| "%02x" % b }.join('')
103
+ end
104
+
105
+ def hex2bin(str)
106
+ [str].pack "H*"
107
+ end
63
108
  def genKey(password)
64
109
  cacheKey = $KeyMap[password]
65
110
  if cacheKey
@@ -80,7 +125,7 @@ module Jekyll
80
125
  cipher.iv = iv
81
126
  cipher.key = genKey password
82
127
  encrypted = cipher.update(msg) + cipher.final
83
- return 'E1.' + Base64.strict_encode64(iv + encrypted + cipher.auth_tag)
128
+ return 'E2.' + Base64.strict_encode64(iv + encrypted + cipher.auth_tag)
84
129
 
85
130
  end
86
131
  def get_encrypt_id(content,page)
@@ -92,7 +137,6 @@ module Jekyll
92
137
  return ""
93
138
  end
94
139
  end
95
-
96
140
  def encrypt_content(content,page,prefix)
97
141
  psw = EncFilterTool.getKey(content,page)
98
142
  psw = prefix + psw + prefix
@@ -123,6 +167,35 @@ module Jekyll
123
167
  return ''
124
168
  end
125
169
 
170
+ def rand_bytes(_,n2)
171
+ return bin2hex(OpenSSL::Random.random_bytes(n2))
172
+ end
173
+
174
+ def encrypt_content_v2(content,pswHex)
175
+ if !pswHex || pswHex.length != 64
176
+ raise "invalid Key:" + pswHex
177
+ end
178
+ cipher = OpenSSL::Cipher::AES.new(256, :CBC).encrypt
179
+ iv = cipher.random_iv
180
+ cipher.iv = iv
181
+ cipher.key = hex2bin(pswHex)
182
+ encrypted = cipher.update(content) + cipher.final
183
+ return 'E2.' + Base64.strict_encode64(iv + encrypted )
184
+ end
185
+
186
+
187
+ def encrypt_key(x,page,keyHex2Enc,encid)
188
+ arr = EncFilterTool.getAllKey(page)
189
+ newArr = arr.map do |k|
190
+ key = genKey encid + k + encid
191
+ hexKey = bin2hex key
192
+ encrypt_content_v2(hex2bin(keyHex2Enc),hexKey)
193
+ end
194
+
195
+ newArr.join('#')
196
+ end
197
+
198
+
126
199
 
127
200
  end
128
201
 
@@ -131,14 +204,6 @@ Liquid::Template.register_filter(Jekyll::EncFilter)
131
204
 
132
205
 
133
206
 
134
- def bin2hex(str)
135
- str.unpack('C*').map{ |b| "%02x" % b }.join('')
136
- end
137
-
138
- def hex2bin(str)
139
- [str].pack "H*"
140
- end
141
-
142
207
 
143
208
 
144
209
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module NoStylePlease2
4
- VERSION = "0.7.4"
4
+ VERSION = "0.8.0"
5
5
  end
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.8.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-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll