Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Npoi
提交
23574ac6
N
Npoi
项目概览
int
/
Npoi
9 个月 前同步成功
通知
2
Star
1
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
Npoi
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
23574ac6
编写于
8月 12, 2023
作者:
G
Gan Keyu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove reflections from poifs.encryption
上级
fd8103d1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
47 addition
and
15 deletion
+47
-15
main/POIFS/Crypt/EncryptionInfo.cs
main/POIFS/Crypt/EncryptionInfo.cs
+38
-11
main/POIFS/Crypt/EncryptionMode.cs
main/POIFS/Crypt/EncryptionMode.cs
+9
-4
未找到文件。
main/POIFS/Crypt/EncryptionInfo.cs
浏览文件 @
23574ac6
...
...
@@ -22,7 +22,8 @@
namespace
NPOI.POIFS.Crypt
{
using
System
;
using
System.Reflection
;
using
System.Diagnostics.CodeAnalysis
;
using
System.Net.Security
;
public
class
EncryptionInfo
{
...
...
@@ -292,23 +293,49 @@ EncryptionMode encryptionMode
_encryptor
=
eib
.
GetEncryptor
();
}
// REMOVE-REFLECTION: Remove reflections here will prevent NPOI from creating custom encryptors.
// Is it OK? Remove reflection-related code for now.
// It might be better to move Agile classes definition into this library. Now it's defined in NPOI.OOXML.Core.
protected
static
IEncryptionInfoBuilder
GetBuilder
(
EncryptionMode
encryptionMode
)
{
Assembly
[]
assemblies
=
AppDomain
.
CurrentDomain
.
GetAssemblies
();
Type
t
=
null
;
foreach
(
Assembly
assembly
in
assemblies
)
switch
(
encryptionMode
.
Builder
)
{
t
=
assembly
.
GetType
(
encryptionMode
.
Builder
);
if
(
t
!=
null
)
case
EncryptionMode
.
BuilderNameBinaryRC4
:
return
new
BinaryRC4
.
BinaryRC4EncryptionInfoBuilder
();
case
EncryptionMode
.
BuilderNameCryptoAPI
:
return
new
CryptoAPI
.
CryptoAPIEncryptionInfoBuilder
();
case
EncryptionMode
.
BuilderNameStandard
:
return
new
Standard
.
StandardEncryptionInfoBuilder
();
case
EncryptionMode
.
BuilderNameAgile
:
// return new Agile.AgileEncryptionInfoBuilder();
// TODO
IEncryptionInfoBuilder
instance
=
CreateAgileInstanceFallback
();
if
(
instance
is
not
null
)
return
instance
;
break
;
}
if
(
t
==
null
)
throw
new
EncryptedDocumentException
(
"Not found type "
+
encryptionMode
.
Builder
);
}
private
static
Type
AgileEncrpytionInfo
;
#if NET6_0_OR_GREATER
[
RequiresUnreferencedCode
(
"Agile must be dynamically loaded from NPOI.OOXML. TODO."
)]
#endif
private
static
IEncryptionInfoBuilder
CreateAgileInstanceFallback
()
{
if
(
AgileEncrpytionInfo
is
null
)
{
throw
new
EncryptedDocumentException
(
"Not found type "
+
encryptionMode
.
Builder
);
foreach
(
var
assembly
in
AppDomain
.
CurrentDomain
.
GetAssemblies
())
if
((
AgileEncrpytionInfo
=
assembly
.
GetType
(
EncryptionMode
.
BuilderNameAgile
))
!=
null
)
break
;
}
IEncryptionInfoBuilder
eib
=
null
;
eib
=
(
IEncryptionInfoBuilder
)
t
.
Assembly
.
CreateInstance
(
encryptionMode
.
Builder
);
return
eib
;
if
(
AgileEncrpytionInfo
is
null
)
return
null
;
return
(
IEncryptionInfoBuilder
)
Activator
.
CreateInstance
(
AgileEncrpytionInfo
);
}
private
int
_versionMajor
;
...
...
main/POIFS/Crypt/EncryptionMode.cs
浏览文件 @
23574ac6
...
...
@@ -27,14 +27,19 @@ namespace NPOI.POIFS.Crypt
*/
public
class
EncryptionMode
{
public
const
string
BuilderNameBinaryRC4
=
"NPOI.POIFS.Crypt.BinaryRC4.BinaryRC4EncryptionInfoBuilder"
;
public
const
string
BuilderNameCryptoAPI
=
"NPOI.POIFS.Crypt.CryptoAPI.CryptoAPIEncryptionInfoBuilder"
;
public
const
string
BuilderNameStandard
=
"NPOI.POIFS.Crypt.Standard.StandardEncryptionInfoBuilder"
;
public
const
string
BuilderNameAgile
=
"NPOI.POIFS.Crypt.Agile.AgileEncryptionInfoBuilder"
;
/* @see <a href="http://msdn.microsoft.com/en-us/library/dd907466(v=office.12).aspx">2.3.6 Office Binary Document RC4 Encryption</a> */
public
static
readonly
EncryptionMode
BinaryRC4
=
new
EncryptionMode
(
"NPOI.POIFS.Crypt.BinaryRC4.BinaryRC4EncryptionInfoBuilder"
,
1
,
1
,
0x0
);
public
static
readonly
EncryptionMode
BinaryRC4
=
new
EncryptionMode
(
BuilderNameBinaryRC4
,
1
,
1
,
0x0
);
/* @see <a href="http://msdn.microsoft.com/en-us/library/dd905225(v=office.12).aspx">2.3.5 Office Binary Document RC4 CryptoAPI Encryption</a> */
public
static
readonly
EncryptionMode
CryptoAPI
=
new
EncryptionMode
(
"NPOI.POIFS.Crypt.CryptoAPI.CryptoAPIEncryptionInfoBuilder"
,
4
,
2
,
0x04
);
public
static
readonly
EncryptionMode
CryptoAPI
=
new
EncryptionMode
(
BuilderNameCryptoAPI
,
4
,
2
,
0x04
);
/* @see <a href="http://msdn.microsoft.com/en-us/library/dd906097(v=office.12).aspx">2.3.4.5 \EncryptionInfo Stream (Standard Encryption)</a> */
public
static
readonly
EncryptionMode
Standard
=
new
EncryptionMode
(
"NPOI.POIFS.Crypt.Standard.StandardEncryptionInfoBuilder"
,
4
,
2
,
0x24
);
public
static
readonly
EncryptionMode
Standard
=
new
EncryptionMode
(
BuilderNameStandard
,
4
,
2
,
0x24
);
/* @see <a href="http://msdn.microsoft.com/en-us/library/dd925810(v=office.12).aspx">2.3.4.10 \EncryptionInfo Stream (Agile Encryption)</a> */
public
static
readonly
EncryptionMode
Agile
=
new
EncryptionMode
(
"NPOI.POIFS.Crypt.Agile.AgileEncryptionInfoBuilder"
,
4
,
4
,
0x40
);
public
static
readonly
EncryptionMode
Agile
=
new
EncryptionMode
(
BuilderNameAgile
,
4
,
4
,
0x40
);
public
string
Builder
{
get
;
private
set
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录