Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
dotNET Platform
runtime
提交
e1fa7874
R
runtime
项目概览
dotNET Platform
/
runtime
10 个月 前同步成功
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
runtime
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
e1fa7874
编写于
4月 17, 2020
作者:
K
Kevin Jones
提交者:
GitHub
4月 17, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Use ReadOnlySpan<byte> instead of byte arrays in CAPI helpers (#35125)
上级
ce416f4c
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
20 addition
and
20 deletion
+20
-20
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptImportKey.cs
...on/src/Interop/Windows/Advapi32/Interop.CryptImportKey.cs
+2
-2
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs
...sp/src/System/Security/Cryptography/CapiHelper.Windows.cs
+11
-9
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/PkcsHelpers.cs
...ryptography.Pkcs/src/Internal/Cryptography/PkcsHelpers.cs
+7
-9
未找到文件。
src/libraries/Common/src/Interop/Windows/Advapi32/Interop.CryptImportKey.cs
浏览文件 @
e1fa7874
...
...
@@ -10,9 +10,9 @@ internal partial class Interop
internal
partial
class
Advapi32
{
[
DllImport
(
Libraries
.
Advapi32
,
CharSet
=
CharSet
.
Unicode
,
SetLastError
=
true
)]
internal
static
extern
bool
CryptImportKey
(
internal
static
extern
unsafe
bool
CryptImportKey
(
SafeProvHandle
hProv
,
byte
[]
pbData
,
byte
*
pbData
,
int
dwDataLen
,
SafeKeyHandle
hPubKey
,
int
dwFlags
,
...
...
src/libraries/System.Security.Cryptography.Csp/src/System/Security/Cryptography/CapiHelper.Windows.cs
浏览文件 @
e1fa7874
...
...
@@ -20,7 +20,7 @@ namespace Internal.NativeCrypto
/// </summary>
internal
static
partial
class
CapiHelper
{
private
static
readonly
byte
[]
s_RgbPubKey
=
private
static
ReadOnlySpan
<
byte
>
RgbPubKey
=>
new
byte
[]
{
0x06
,
0x02
,
0x00
,
0x00
,
0x00
,
0xa4
,
0x00
,
0x00
,
0x52
,
0x53
,
0x41
,
0x31
,
0x00
,
0x02
,
0x00
,
0x00
,
...
...
@@ -1022,7 +1022,7 @@ internal static void ImportKeyBlob(SafeProvHandle saveProvHandle, CspProviderFla
}
SafeKeyHandle
hKey
;
if
(!
CryptImportKey
(
saveProvHandle
,
keyBlob
,
keyBlob
.
Length
,
SafeKeyHandle
.
InvalidHandle
,
dwCapiFlags
,
out
hKey
))
if
(!
CryptImportKey
(
saveProvHandle
,
keyBlob
,
SafeKeyHandle
.
InvalidHandle
,
dwCapiFlags
,
out
hKey
))
{
int
hr
=
Marshal
.
GetHRForLastWin32Error
();
...
...
@@ -1330,7 +1330,7 @@ private static void UnloadKey(SafeProvHandle hProv, SafeKeyHandle hKey, [NotNull
try
{
// Import the public key
if
(!
CryptImportKey
(
hProv
,
s_RgbPubKey
,
s_RgbPubKey
.
Length
,
SafeKeyHandle
.
InvalidHandle
,
0
,
out
hPubKey
))
if
(!
CryptImportKey
(
hProv
,
RgbPubKey
,
SafeKeyHandle
.
InvalidHandle
,
0
,
out
hPubKey
))
{
int
hr
=
Marshal
.
GetHRForLastWin32Error
();
throw
hr
.
ToCryptographicException
();
...
...
@@ -1469,19 +1469,21 @@ public static CryptographicException GetEFailException()
return
response
;
}
public
static
bool
CryptImportKey
(
public
static
unsafe
bool
CryptImportKey
(
SafeProvHandle
hProv
,
byte
[]
pbData
,
int
dwDataLen
,
ReadOnlySpan
<
byte
>
pbData
,
SafeKeyHandle
hPubKey
,
int
dwFlags
,
out
SafeKeyHandle
phKey
)
{
bool
response
=
Interop
.
Advapi32
.
CryptImportKey
(
hProv
,
pbData
,
dwDataLen
,
hPubKey
,
dwFlags
,
out
phKey
);
fixed
(
byte
*
pbDataPtr
=
pbData
)
{
bool
response
=
Interop
.
Advapi32
.
CryptImportKey
(
hProv
,
pbDataPtr
,
pbData
.
Length
,
hPubKey
,
dwFlags
,
out
phKey
);
phKey
.
SetParent
(
hProv
);
phKey
.
SetParent
(
hProv
);
return
response
;
return
response
;
}
}
public
static
bool
CryptCreateHash
(
...
...
src/libraries/System.Security.Cryptography.Pkcs/src/Internal/Cryptography/PkcsHelpers.cs
浏览文件 @
e1fa7874
...
...
@@ -21,8 +21,6 @@ namespace Internal.Cryptography
{
internal
static
partial
class
PkcsHelpers
{
private
static
readonly
byte
[]
s_pSpecifiedDefaultParameters
=
{
0x04
,
0x00
};
#if !NETCOREAPP && !NETSTANDARD2_1
// Compatibility API.
internal
static
void
AppendData
(
this
IncrementalHash
hasher
,
ReadOnlySpan
<
byte
>
data
)
...
...
@@ -532,8 +530,6 @@ public static byte[] EncodeOctetString(byte[] octets)
}
}
private
static
readonly
byte
[]
s_invalidEmptyOid
=
{
0x06
,
0x00
};
public
static
byte
[]
EncodeUtcTime
(
DateTime
utcTime
)
{
const
int
maxLegalYear
=
2049
;
...
...
@@ -573,16 +569,16 @@ public static DateTime DecodeUtcTime(byte[] encodedUtcTime)
return
value
.
UtcDateTime
;
}
public
static
string
DecodeOid
(
byte
[]
encodedOid
)
public
static
string
DecodeOid
(
ReadOnlySpan
<
byte
>
encodedOid
)
{
// Windows compat.
if
(
s_invalidEmptyOid
.
AsSpan
().
SequenceEqual
(
encodedOid
)
)
// Windows compat
for a zero length OID
.
if
(
encodedOid
.
Length
==
2
&&
encodedOid
[
0
]
==
0x06
&&
encodedOid
[
1
]
==
0x00
)
{
return
string
.
Empty
;
}
// Read using BER because the CMS specification says the encoding is BER.
Asn
Reader
reader
=
new
Asn
Reader
(
encodedOid
,
AsnEncodingRules
.
BER
);
Asn
ValueReader
reader
=
new
AsnValue
Reader
(
encodedOid
,
AsnEncodingRules
.
BER
);
string
value
=
reader
.
ReadObjectIdentifierAsString
();
reader
.
ThrowIfNotEmpty
();
return
value
;
...
...
@@ -623,8 +619,10 @@ public static string DecodeOid(byte[] encodedOid)
return
false
;
}
ReadOnlySpan
<
byte
>
pSpecifiedDefaultParameters
=
new
byte
[]
{
0x04
,
0x00
};
if
(
oaepParameters
.
PSourceFunc
.
Parameters
!=
null
&&
!
oaepParameters
.
PSourceFunc
.
Parameters
.
Value
.
Span
.
SequenceEqual
(
s_
pSpecifiedDefaultParameters
))
!
oaepParameters
.
PSourceFunc
.
Parameters
.
Value
.
Span
.
SequenceEqual
(
pSpecifiedDefaultParameters
))
{
exception
=
new
CryptographicException
(
SR
.
Cryptography_Der_Invalid_Encoding
);
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录