Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录/注册
切换导航
H
h2database
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
Administrator
h2database
Commits
3b457ffc
提交
3b457ffc
authored
5月 30, 2011
作者:
Thomas Mueller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
StringUtils.convertBytesToHex
上级
27d7caa1
隐藏空白字符变更
内嵌
并排
正在显示
18 个修改的文件
包含
45 行增加
和
47 行删除
+45
-47
TraceObject.java
h2/src/main/org/h2/message/TraceObject.java
+1
-1
CipherFactory.java
h2/src/main/org/h2/security/CipherFactory.java
+2
-2
WebApp.java
h2/src/main/org/h2/server/web/WebApp.java
+1
-1
WebServer.java
h2/src/main/org/h2/server/web/WebServer.java
+1
-1
FileLock.java
h2/src/main/org/h2/store/FileLock.java
+1
-1
FileSystem.java
h2/src/main/org/h2/store/fs/FileSystem.java
+1
-1
Recover.java
h2/src/main/org/h2/tools/Recover.java
+2
-2
StringUtils.java
h2/src/main/org/h2/util/StringUtils.java
+4
-6
Value.java
h2/src/main/org/h2/value/Value.java
+3
-3
ValueBytes.java
h2/src/main/org/h2/value/ValueBytes.java
+1
-1
ValueLob.java
h2/src/main/org/h2/value/ValueLob.java
+2
-2
ValueLobDb.java
h2/src/main/org/h2/value/ValueLobDb.java
+2
-2
ValueUuid.java
h2/src/main/org/h2/value/ValueUuid.java
+1
-1
TestCsv.java
h2/src/test/org/h2/test/db/TestCsv.java
+1
-1
TestSecurity.java
h2/src/test/org/h2/test/unit/TestSecurity.java
+13
-13
TestStringUtils.java
h2/src/test/org/h2/test/unit/TestStringUtils.java
+6
-6
FileObjectCrypt.java
h2/src/tools/org/h2/dev/fs/FileObjectCrypt.java
+1
-1
SecureKeyStoreBuilder.java
h2/src/tools/org/h2/dev/security/SecureKeyStoreBuilder.java
+2
-2
没有找到文件。
h2/src/main/org/h2/message/TraceObject.java
浏览文件 @
3b457ffc
...
@@ -318,7 +318,7 @@ public class TraceObject {
...
@@ -318,7 +318,7 @@ public class TraceObject {
if
(
x
==
null
)
{
if
(
x
==
null
)
{
return
"null"
;
return
"null"
;
}
}
return
"org.h2.util.StringUtils.convert
StringToBytes(\""
+
StringUtils
.
convertBytesToString
(
x
)
+
"\")"
;
return
"org.h2.util.StringUtils.convert
HexToBytes(\""
+
StringUtils
.
convertBytesToHex
(
x
)
+
"\")"
;
}
}
/**
/**
...
...
h2/src/main/org/h2/security/CipherFactory.java
浏览文件 @
3b457ffc
...
@@ -153,13 +153,13 @@ public class CipherFactory {
...
@@ -153,13 +153,13 @@ public class CipherFactory {
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
KeyFactory
keyFactory
=
KeyFactory
.
getInstance
(
"RSA"
);
store
.
load
(
null
,
password
.
toCharArray
());
store
.
load
(
null
,
password
.
toCharArray
());
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
PKCS8EncodedKeySpec
keySpec
=
new
PKCS8EncodedKeySpec
(
StringUtils
.
convert
String
ToBytes
(
"30820277020100300d06092a864886f70d0101010500048202613082025d02010002818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d02030100010281810099aa4ff4d0a09a5af0bd953cb10c4d08c3d98df565664ac5582e494314d5c3c92dddedd5d316a32a206be4ec084616fe57be15e27cad111aa3c21fa79e32258c6ca8430afc69eddd52d3b751b37da6b6860910b94653192c0db1d02abcfd6ce14c01f238eec7c20bd3bb750940004bacba2880349a9494d10e139ecb2355d101024100ffdc3defd9c05a2d377ef6019fa62b3fbd5b0020a04cc8533bca730e1f6fcf5dfceea1b044fbe17d9eababfbc7d955edad6bc60f9be826ad2c22ba77d19a9f65024100dc28d43fdbbc93852cc3567093157702bc16f156f709fb7db0d9eec028f41fd0edcd17224c866e66be1744141fb724a10fd741c8a96afdd9141b36d67fff6309024077b1cddbde0f69604bdcfe33263fb36ddf24aa3b9922327915b890f8a36648295d0139ecdf68c245652c4489c6257b58744fbdd961834a4cab201801a3b1e52d024100b17142e8991d1b350a0802624759d48ae2b8071a158ff91fabeb6a8f7c328e762143dc726b8529f42b1fab6220d1c676fdc27ba5d44e847c72c52064afd351a902407c6e23fe35bcfcd1a662aa82a2aa725fcece311644d5b6e3894853fd4ce9fe78218c957b1ff03fc9e5ef8ffeb6bd58235f6a215c97d354fdace7e781e4a63e8b"
));
StringUtils
.
convert
Hex
ToBytes
(
"30820277020100300d06092a864886f70d0101010500048202613082025d02010002818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d02030100010281810099aa4ff4d0a09a5af0bd953cb10c4d08c3d98df565664ac5582e494314d5c3c92dddedd5d316a32a206be4ec084616fe57be15e27cad111aa3c21fa79e32258c6ca8430afc69eddd52d3b751b37da6b6860910b94653192c0db1d02abcfd6ce14c01f238eec7c20bd3bb750940004bacba2880349a9494d10e139ecb2355d101024100ffdc3defd9c05a2d377ef6019fa62b3fbd5b0020a04cc8533bca730e1f6fcf5dfceea1b044fbe17d9eababfbc7d955edad6bc60f9be826ad2c22ba77d19a9f65024100dc28d43fdbbc93852cc3567093157702bc16f156f709fb7db0d9eec028f41fd0edcd17224c866e66be1744141fb724a10fd741c8a96afdd9141b36d67fff6309024077b1cddbde0f69604bdcfe33263fb36ddf24aa3b9922327915b890f8a36648295d0139ecdf68c245652c4489c6257b58744fbdd961834a4cab201801a3b1e52d024100b17142e8991d1b350a0802624759d48ae2b8071a158ff91fabeb6a8f7c328e762143dc726b8529f42b1fab6220d1c676fdc27ba5d44e847c72c52064afd351a902407c6e23fe35bcfcd1a662aa82a2aa725fcece311644d5b6e3894853fd4ce9fe78218c957b1ff03fc9e5ef8ffeb6bd58235f6a215c97d354fdace7e781e4a63e8b"
));
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
PrivateKey
privateKey
=
keyFactory
.
generatePrivate
(
keySpec
);
Certificate
[]
certs
=
{
CertificateFactory
Certificate
[]
certs
=
{
CertificateFactory
.
getInstance
(
"X.509"
)
.
getInstance
(
"X.509"
)
.
generateCertificate
(
.
generateCertificate
(
new
ByteArrayInputStream
(
new
ByteArrayInputStream
(
StringUtils
.
convert
String
ToBytes
(
"3082018b3081f502044295ce6b300d06092a864886f70d0101040500300d310b3009060355040313024832301e170d3035303532363133323630335a170d3337303933303036353734375a300d310b300906035504031302483230819f300d06092a864886f70d010101050003818d0030818902818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d0203010001300d06092a864886f70d01010405000381810083f4401a279453701bef9a7681a5b8b24f153f7d18c7c892133d97bd5f13736be7505290a445a7d5ceb75522403e5097515cd966ded6351ff60d5193de34cd36e5cb04d380398e66286f99923fd92296645fd4ada45844d194dfd815e6cd57f385c117be982809028bba1116c85740b3d27a55b1a0948bf291ddba44bed337b9"
))),
};
StringUtils
.
convert
Hex
ToBytes
(
"3082018b3081f502044295ce6b300d06092a864886f70d0101040500300d310b3009060355040313024832301e170d3035303532363133323630335a170d3337303933303036353734375a300d310b300906035504031302483230819f300d06092a864886f70d010101050003818d0030818902818100dc0a13c602b7141110eade2f051b54777b060d0f74e6a110f9cce81159f271ebc88d8e8aa1f743b505fc2e7dfe38d33b8d3f64d1b363d1af4d877833897954cbaec2fa384c22a415498cf306bb07ac09b76b001cd68bf77ea0a628f5101959cf2993a9c23dbee79b19305977f8715ae78d023471194cc900b231eecb0aaea98d0203010001300d06092a864886f70d01010405000381810083f4401a279453701bef9a7681a5b8b24f153f7d18c7c892133d97bd5f13736be7505290a445a7d5ceb75522403e5097515cd966ded6351ff60d5193de34cd36e5cb04d380398e66286f99923fd92296645fd4ada45844d194dfd815e6cd57f385c117be982809028bba1116c85740b3d27a55b1a0948bf291ddba44bed337b9"
))),
};
store
.
setKeyEntry
(
"h2"
,
privateKey
,
password
.
toCharArray
(),
certs
);
store
.
setKeyEntry
(
"h2"
,
privateKey
,
password
.
toCharArray
(),
certs
);
// --- generated code end ---
// --- generated code end ---
return
store
;
return
store
;
...
...
h2/src/main/org/h2/server/web/WebApp.java
浏览文件 @
3b457ffc
...
@@ -1263,7 +1263,7 @@ public class WebApp {
...
@@ -1263,7 +1263,7 @@ public class WebApp {
}
else
if
(
isBuiltIn
(
sql
,
"@password_hash"
))
{
}
else
if
(
isBuiltIn
(
sql
,
"@password_hash"
))
{
sql
=
sql
.
substring
(
"@password_hash"
.
length
()).
trim
();
sql
=
sql
.
substring
(
"@password_hash"
.
length
()).
trim
();
String
[]
p
=
split
(
sql
);
String
[]
p
=
split
(
sql
);
return
StringUtils
.
convertBytesTo
String
(
SHA256
.
getKeyPasswordHash
(
p
[
0
],
p
[
1
].
toCharArray
()));
return
StringUtils
.
convertBytesTo
Hex
(
SHA256
.
getKeyPasswordHash
(
p
[
0
],
p
[
1
].
toCharArray
()));
}
else
if
(
isBuiltIn
(
sql
,
"@prof_start"
))
{
}
else
if
(
isBuiltIn
(
sql
,
"@prof_start"
))
{
if
(
profiler
!=
null
)
{
if
(
profiler
!=
null
)
{
profiler
.
stopCollecting
();
profiler
.
stopCollecting
();
...
...
h2/src/main/org/h2/server/web/WebServer.java
浏览文件 @
3b457ffc
...
@@ -198,7 +198,7 @@ public class WebServer implements Service {
...
@@ -198,7 +198,7 @@ public class WebServer implements Service {
private
static
String
generateSessionId
()
{
private
static
String
generateSessionId
()
{
byte
[]
buff
=
MathUtils
.
secureRandomBytes
(
16
);
byte
[]
buff
=
MathUtils
.
secureRandomBytes
(
16
);
return
StringUtils
.
convertBytesTo
String
(
buff
);
return
StringUtils
.
convertBytesTo
Hex
(
buff
);
}
}
/**
/**
...
...
h2/src/main/org/h2/store/FileLock.java
浏览文件 @
3b457ffc
...
@@ -295,7 +295,7 @@ public class FileLock implements Runnable {
...
@@ -295,7 +295,7 @@ public class FileLock implements Runnable {
private
void
setUniqueId
()
{
private
void
setUniqueId
()
{
byte
[]
bytes
=
MathUtils
.
secureRandomBytes
(
RANDOM_BYTES
);
byte
[]
bytes
=
MathUtils
.
secureRandomBytes
(
RANDOM_BYTES
);
String
random
=
StringUtils
.
convertBytesTo
String
(
bytes
);
String
random
=
StringUtils
.
convertBytesTo
Hex
(
bytes
);
uniqueId
=
Long
.
toHexString
(
System
.
currentTimeMillis
())
+
random
;
uniqueId
=
Long
.
toHexString
(
System
.
currentTimeMillis
())
+
random
;
properties
.
setProperty
(
"id"
,
uniqueId
);
properties
.
setProperty
(
"id"
,
uniqueId
);
}
}
...
...
h2/src/main/org/h2/store/fs/FileSystem.java
浏览文件 @
3b457ffc
...
@@ -283,7 +283,7 @@ public abstract class FileSystem {
...
@@ -283,7 +283,7 @@ public abstract class FileSystem {
if
(
newRandom
||
tempRandom
==
null
)
{
if
(
newRandom
||
tempRandom
==
null
)
{
byte
[]
prefix
=
new
byte
[
8
];
byte
[]
prefix
=
new
byte
[
8
];
MathUtils
.
randomBytes
(
prefix
);
MathUtils
.
randomBytes
(
prefix
);
tempRandom
=
StringUtils
.
convertBytesTo
String
(
prefix
)
+
"."
;
tempRandom
=
StringUtils
.
convertBytesTo
Hex
(
prefix
)
+
"."
;
}
}
return
tempRandom
+
tempSequence
++;
return
tempRandom
+
tempSequence
++;
}
}
...
...
h2/src/main/org/h2/tools/Recover.java
浏览文件 @
3b457ffc
...
@@ -1095,9 +1095,9 @@ public class Recover extends Tool implements DataHandler {
...
@@ -1095,9 +1095,9 @@ public class Recover extends Tool implements DataHandler {
byte
[]
passwordHash
=
SHA256
.
getHashWithSalt
(
userPasswordHash
,
salt
);
byte
[]
passwordHash
=
SHA256
.
getHashWithSalt
(
userPasswordHash
,
salt
);
StringBuilder
buff
=
new
StringBuilder
();
StringBuilder
buff
=
new
StringBuilder
();
buff
.
append
(
"SALT '"
).
buff
.
append
(
"SALT '"
).
append
(
StringUtils
.
convertBytesTo
String
(
salt
)).
append
(
StringUtils
.
convertBytesTo
Hex
(
salt
)).
append
(
"' HASH '"
).
append
(
"' HASH '"
).
append
(
StringUtils
.
convertBytesTo
String
(
passwordHash
)).
append
(
StringUtils
.
convertBytesTo
Hex
(
passwordHash
)).
append
(
'\''
);
append
(
'\''
);
byte
[]
replacement
=
buff
.
toString
().
getBytes
();
byte
[]
replacement
=
buff
.
toString
().
getBytes
();
System
.
arraycopy
(
replacement
,
0
,
s
.
getBytes
(),
saltIndex
,
replacement
.
length
);
System
.
arraycopy
(
replacement
,
0
,
s
.
getBytes
(),
saltIndex
,
replacement
.
length
);
...
...
h2/src/main/org/h2/util/StringUtils.java
浏览文件 @
3b457ffc
...
@@ -937,7 +937,7 @@ public class StringUtils {
...
@@ -937,7 +937,7 @@ public class StringUtils {
* @param s the hex encoded string
* @param s the hex encoded string
* @return the byte array
* @return the byte array
*/
*/
public
static
byte
[]
convert
String
ToBytes
(
String
s
)
{
public
static
byte
[]
convert
Hex
ToBytes
(
String
s
)
{
int
len
=
s
.
length
();
int
len
=
s
.
length
();
if
(
len
%
2
!=
0
)
{
if
(
len
%
2
!=
0
)
{
throw
DbException
.
get
(
ErrorCode
.
HEX_STRING_ODD_1
,
s
);
throw
DbException
.
get
(
ErrorCode
.
HEX_STRING_ODD_1
,
s
);
...
@@ -969,8 +969,8 @@ public class StringUtils {
...
@@ -969,8 +969,8 @@ public class StringUtils {
* @param value the byte array
* @param value the byte array
* @return the hex encoded string
* @return the hex encoded string
*/
*/
public
static
String
convertBytesTo
String
(
byte
[]
value
)
{
public
static
String
convertBytesTo
Hex
(
byte
[]
value
)
{
return
convertBytesTo
String
(
value
,
value
.
length
);
return
convertBytesTo
Hex
(
value
,
value
.
length
);
}
}
/**
/**
...
@@ -980,7 +980,7 @@ public class StringUtils {
...
@@ -980,7 +980,7 @@ public class StringUtils {
* @param len the number of bytes to encode
* @param len the number of bytes to encode
* @return the hex encoded string
* @return the hex encoded string
*/
*/
public
static
String
convertBytesTo
String
(
byte
[]
value
,
int
len
)
{
public
static
String
convertBytesTo
Hex
(
byte
[]
value
,
int
len
)
{
char
[]
buff
=
new
char
[
len
+
len
];
char
[]
buff
=
new
char
[
len
+
len
];
char
[]
hex
=
HEX
;
char
[]
hex
=
HEX
;
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
for
(
int
i
=
0
;
i
<
len
;
i
++)
{
...
@@ -1009,6 +1009,4 @@ public class StringUtils {
...
@@ -1009,6 +1009,4 @@ public class StringUtils {
return
true
;
return
true
;
}
}
}
}
h2/src/main/org/h2/value/Value.java
浏览文件 @
3b457ffc
...
@@ -813,9 +813,9 @@ public abstract class Value {
...
@@ -813,9 +813,9 @@ public abstract class Value {
case
TIMESTAMP:
case
TIMESTAMP:
return
ValueTimestamp
.
getNoCopy
(
ValueTimestamp
.
parseTimestamp
(
s
.
trim
()));
return
ValueTimestamp
.
getNoCopy
(
ValueTimestamp
.
parseTimestamp
(
s
.
trim
()));
case
BYTES:
case
BYTES:
return
ValueBytes
.
getNoCopy
(
StringUtils
.
convert
String
ToBytes
(
s
.
trim
()));
return
ValueBytes
.
getNoCopy
(
StringUtils
.
convert
Hex
ToBytes
(
s
.
trim
()));
case
JAVA_OBJECT:
case
JAVA_OBJECT:
return
ValueJavaObject
.
getNoCopy
(
StringUtils
.
convert
String
ToBytes
(
s
.
trim
()));
return
ValueJavaObject
.
getNoCopy
(
StringUtils
.
convert
Hex
ToBytes
(
s
.
trim
()));
case
STRING:
case
STRING:
return
ValueString
.
get
(
s
);
return
ValueString
.
get
(
s
);
case
STRING_IGNORECASE:
case
STRING_IGNORECASE:
...
@@ -829,7 +829,7 @@ public abstract class Value {
...
@@ -829,7 +829,7 @@ public abstract class Value {
case
CLOB:
case
CLOB:
return
LobStorage
.
createSmallLob
(
CLOB
,
StringUtils
.
utf8Encode
(
s
));
return
LobStorage
.
createSmallLob
(
CLOB
,
StringUtils
.
utf8Encode
(
s
));
case
BLOB:
case
BLOB:
return
LobStorage
.
createSmallLob
(
BLOB
,
StringUtils
.
convert
String
ToBytes
(
s
.
trim
()));
return
LobStorage
.
createSmallLob
(
BLOB
,
StringUtils
.
convert
Hex
ToBytes
(
s
.
trim
()));
case
ARRAY:
case
ARRAY:
return
ValueArray
.
get
(
new
Value
[]{
ValueString
.
get
(
s
)});
return
ValueArray
.
get
(
new
Value
[]{
ValueString
.
get
(
s
)});
case
RESULT_SET:
{
case
RESULT_SET:
{
...
...
h2/src/main/org/h2/value/ValueBytes.java
浏览文件 @
3b457ffc
...
@@ -83,7 +83,7 @@ public class ValueBytes extends Value {
...
@@ -83,7 +83,7 @@ public class ValueBytes extends Value {
}
}
public
String
getString
()
{
public
String
getString
()
{
return
StringUtils
.
convertBytesTo
String
(
value
);
return
StringUtils
.
convertBytesTo
Hex
(
value
);
}
}
public
long
getPrecision
()
{
public
long
getPrecision
()
{
...
...
h2/src/main/org/h2/value/ValueLob.java
浏览文件 @
3b457ffc
...
@@ -552,7 +552,7 @@ public class ValueLob extends Value {
...
@@ -552,7 +552,7 @@ public class ValueLob extends Value {
}
else
{
}
else
{
buff
=
IOUtils
.
readBytesAndClose
(
getInputStream
(),
len
);
buff
=
IOUtils
.
readBytesAndClose
(
getInputStream
(),
len
);
}
}
return
StringUtils
.
convertBytesTo
String
(
buff
);
return
StringUtils
.
convertBytesTo
Hex
(
buff
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
fileName
);
throw
DbException
.
convertIOException
(
e
,
fileName
);
}
}
...
@@ -646,7 +646,7 @@ public class ValueLob extends Value {
...
@@ -646,7 +646,7 @@ public class ValueLob extends Value {
return
StringUtils
.
quoteStringSQL
(
s
);
return
StringUtils
.
quoteStringSQL
(
s
);
}
}
byte
[]
buff
=
getBytes
();
byte
[]
buff
=
getBytes
();
s
=
StringUtils
.
convertBytesTo
String
(
buff
);
s
=
StringUtils
.
convertBytesTo
Hex
(
buff
);
return
"X'"
+
s
+
"'"
;
return
"X'"
+
s
+
"'"
;
}
}
...
...
h2/src/main/org/h2/value/ValueLobDb.java
浏览文件 @
3b457ffc
...
@@ -192,7 +192,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
...
@@ -192,7 +192,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
}
else
{
}
else
{
buff
=
IOUtils
.
readBytesAndClose
(
getInputStream
(),
len
);
buff
=
IOUtils
.
readBytesAndClose
(
getInputStream
(),
len
);
}
}
return
StringUtils
.
convertBytesTo
String
(
buff
);
return
StringUtils
.
convertBytesTo
Hex
(
buff
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
DbException
.
convertIOException
(
e
,
toString
());
throw
DbException
.
convertIOException
(
e
,
toString
());
}
}
...
@@ -302,7 +302,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
...
@@ -302,7 +302,7 @@ public class ValueLobDb extends Value implements Value.ValueClob, Value.ValueBlo
return
StringUtils
.
quoteStringSQL
(
s
);
return
StringUtils
.
quoteStringSQL
(
s
);
}
}
byte
[]
buff
=
getBytes
();
byte
[]
buff
=
getBytes
();
s
=
StringUtils
.
convertBytesTo
String
(
buff
);
s
=
StringUtils
.
convertBytesTo
Hex
(
buff
);
return
"X'"
+
s
+
"'"
;
return
"X'"
+
s
+
"'"
;
}
}
...
...
h2/src/main/org/h2/value/ValueUuid.java
浏览文件 @
3b457ffc
...
@@ -64,7 +64,7 @@ public class ValueUuid extends Value {
...
@@ -64,7 +64,7 @@ public class ValueUuid extends Value {
*/
*/
public
static
ValueUuid
get
(
byte
[]
binary
)
{
public
static
ValueUuid
get
(
byte
[]
binary
)
{
if
(
binary
.
length
<
16
)
{
if
(
binary
.
length
<
16
)
{
return
get
(
StringUtils
.
convertBytesTo
String
(
binary
));
return
get
(
StringUtils
.
convertBytesTo
Hex
(
binary
));
}
}
long
high
=
Utils
.
readLong
(
binary
,
0
);
long
high
=
Utils
.
readLong
(
binary
,
0
);
long
low
=
Utils
.
readLong
(
binary
,
8
);
long
low
=
Utils
.
readLong
(
binary
,
8
);
...
...
h2/src/test/org/h2/test/db/TestCsv.java
浏览文件 @
3b457ffc
...
@@ -152,7 +152,7 @@ public class TestCsv extends TestBase {
...
@@ -152,7 +152,7 @@ public class TestCsv extends TestBase {
private
void
testPseudoBom
()
throws
Exception
{
private
void
testPseudoBom
()
throws
Exception
{
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
out
=
new
ByteArrayOutputStream
();
// UTF-8 "BOM" / marker
// UTF-8 "BOM" / marker
out
.
write
(
StringUtils
.
convert
String
ToBytes
(
"ef"
+
"bb"
+
"bf"
));
out
.
write
(
StringUtils
.
convert
Hex
ToBytes
(
"ef"
+
"bb"
+
"bf"
));
out
.
write
(
"\"ID\", \"NAME\"\n1, Hello"
.
getBytes
(
"UTF-8"
));
out
.
write
(
"\"ID\", \"NAME\"\n1, Hello"
.
getBytes
(
"UTF-8"
));
byte
[]
buff
=
out
.
toByteArray
();
byte
[]
buff
=
out
.
toByteArray
();
Reader
r
=
new
InputStreamReader
(
new
ByteArrayInputStream
(
buff
),
"UTF-8"
);
Reader
r
=
new
InputStreamReader
(
new
ByteArrayInputStream
(
buff
),
"UTF-8"
);
...
...
h2/src/test/org/h2/test/unit/TestSecurity.java
浏览文件 @
3b457ffc
...
@@ -39,7 +39,7 @@ public class TestSecurity extends TestBase {
...
@@ -39,7 +39,7 @@ public class TestSecurity extends TestBase {
private
static
void
testConnectWithHash
()
throws
SQLException
{
private
static
void
testConnectWithHash
()
throws
SQLException
{
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test"
,
"sa"
,
"sa"
);
Connection
conn
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test"
,
"sa"
,
"sa"
);
String
pwd
=
StringUtils
.
convertBytesTo
String
(
SHA256
.
getKeyPasswordHash
(
"SA"
,
"sa"
.
toCharArray
()));
String
pwd
=
StringUtils
.
convertBytesTo
Hex
(
SHA256
.
getKeyPasswordHash
(
"SA"
,
"sa"
.
toCharArray
()));
Connection
conn2
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test;PASSWORD_HASH=TRUE"
,
"sa"
,
pwd
);
Connection
conn2
=
DriverManager
.
getConnection
(
"jdbc:h2:mem:test;PASSWORD_HASH=TRUE"
,
"sa"
,
pwd
);
conn
.
close
();
conn
.
close
();
conn2
.
close
();
conn2
.
close
();
...
@@ -54,7 +54,7 @@ public class TestSecurity extends TestBase {
...
@@ -54,7 +54,7 @@ public class TestSecurity extends TestBase {
if
(
data
.
length
>
0
)
{
if
(
data
.
length
>
0
)
{
assertEquals
(
0
,
data
[
0
]);
assertEquals
(
0
,
data
[
0
]);
}
}
return
StringUtils
.
convertBytesTo
String
(
result
);
return
StringUtils
.
convertBytesTo
Hex
(
result
);
}
}
private
void
testOneSHA
()
{
private
void
testOneSHA
()
{
...
@@ -79,7 +79,7 @@ public class TestSecurity extends TestBase {
...
@@ -79,7 +79,7 @@ public class TestSecurity extends TestBase {
}
}
private
void
checkSHA256
(
String
message
,
String
expected
)
{
private
void
checkSHA256
(
String
message
,
String
expected
)
{
String
hash
=
StringUtils
.
convertBytesTo
String
(
SHA256
.
getHash
(
message
.
getBytes
(),
true
)).
toUpperCase
();
String
hash
=
StringUtils
.
convertBytesTo
Hex
(
SHA256
.
getHash
(
message
.
getBytes
(),
true
)).
toUpperCase
();
assertEquals
(
expected
,
hash
);
assertEquals
(
expected
,
hash
);
}
}
...
@@ -102,28 +102,28 @@ public class TestSecurity extends TestBase {
...
@@ -102,28 +102,28 @@ public class TestSecurity extends TestBase {
// http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip
// http://csrc.nist.gov/groups/STM/cavp/documents/aes/KAT_AES.zip
// ECBVarTxt128e.txt
// ECBVarTxt128e.txt
// COUNT = 0
// COUNT = 0
test
.
setKey
(
StringUtils
.
convert
String
ToBytes
(
"00000000000000000000000000000000"
));
test
.
setKey
(
StringUtils
.
convert
Hex
ToBytes
(
"00000000000000000000000000000000"
));
data
=
StringUtils
.
convert
String
ToBytes
(
"80000000000000000000000000000000"
);
data
=
StringUtils
.
convert
Hex
ToBytes
(
"80000000000000000000000000000000"
);
test
.
encrypt
(
data
,
0
,
data
.
length
);
test
.
encrypt
(
data
,
0
,
data
.
length
);
r
=
StringUtils
.
convertBytesTo
String
(
data
);
r
=
StringUtils
.
convertBytesTo
Hex
(
data
);
assertEquals
(
"3ad78e726c1ec02b7ebfe92b23d9ec34"
,
r
);
assertEquals
(
"3ad78e726c1ec02b7ebfe92b23d9ec34"
,
r
);
// COUNT = 127
// COUNT = 127
test
.
setKey
(
StringUtils
.
convert
String
ToBytes
(
"00000000000000000000000000000000"
));
test
.
setKey
(
StringUtils
.
convert
Hex
ToBytes
(
"00000000000000000000000000000000"
));
data
=
StringUtils
.
convert
String
ToBytes
(
"ffffffffffffffffffffffffffffffff"
);
data
=
StringUtils
.
convert
Hex
ToBytes
(
"ffffffffffffffffffffffffffffffff"
);
test
.
encrypt
(
data
,
0
,
data
.
length
);
test
.
encrypt
(
data
,
0
,
data
.
length
);
r
=
StringUtils
.
convertBytesTo
String
(
data
);
r
=
StringUtils
.
convertBytesTo
Hex
(
data
);
assertEquals
(
"3f5b8cc9ea855a0afa7347d23e8d664e"
,
r
);
assertEquals
(
"3f5b8cc9ea855a0afa7347d23e8d664e"
,
r
);
// test vector from
// test vector from
// http://www.inconteam.com/index.php?option=com_content&view=article&id=55:aes-test-vectors&catid=41:encryption&Itemid=60#aes-ecb-128
// http://www.inconteam.com/index.php?option=com_content&view=article&id=55:aes-test-vectors&catid=41:encryption&Itemid=60#aes-ecb-128
test
.
setKey
(
StringUtils
.
convert
String
ToBytes
(
"2b7e151628aed2a6abf7158809cf4f3c"
));
test
.
setKey
(
StringUtils
.
convert
Hex
ToBytes
(
"2b7e151628aed2a6abf7158809cf4f3c"
));
data
=
StringUtils
.
convert
String
ToBytes
(
"6bc1bee22e409f96e93d7e117393172a"
);
data
=
StringUtils
.
convert
Hex
ToBytes
(
"6bc1bee22e409f96e93d7e117393172a"
);
test
.
encrypt
(
data
,
0
,
data
.
length
);
test
.
encrypt
(
data
,
0
,
data
.
length
);
r
=
StringUtils
.
convertBytesTo
String
(
data
);
r
=
StringUtils
.
convertBytesTo
Hex
(
data
);
assertEquals
(
"3ad77bb40d7a3660a89ecaf32466ef97"
,
r
);
assertEquals
(
"3ad77bb40d7a3660a89ecaf32466ef97"
,
r
);
test
.
setKey
(
StringUtils
.
convert
String
ToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
test
.
setKey
(
StringUtils
.
convert
Hex
ToBytes
(
"000102030405060708090A0B0C0D0E0F"
));
byte
[]
in
=
new
byte
[
128
];
byte
[]
in
=
new
byte
[
128
];
byte
[]
enc
=
new
byte
[
128
];
byte
[]
enc
=
new
byte
[
128
];
test
.
encrypt
(
enc
,
0
,
128
);
test
.
encrypt
(
enc
,
0
,
128
);
...
...
h2/src/test/org/h2/test/unit/TestStringUtils.java
浏览文件 @
3b457ffc
...
@@ -41,18 +41,18 @@ public class TestStringUtils extends TestBase {
...
@@ -41,18 +41,18 @@ public class TestStringUtils extends TestBase {
}
}
private
void
testHex
()
{
private
void
testHex
()
{
assertEquals
(
"face"
,
StringUtils
.
convertBytesTo
String
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
}));
assertEquals
(
"face"
,
StringUtils
.
convertBytesTo
Hex
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
}));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
StringUtils
.
convert
String
ToBytes
(
"face"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
StringUtils
.
convert
Hex
ToBytes
(
"face"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
StringUtils
.
convert
String
ToBytes
(
"fAcE"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
StringUtils
.
convert
Hex
ToBytes
(
"fAcE"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
StringUtils
.
convert
String
ToBytes
(
"FaCe"
));
assertEquals
(
new
byte
[]
{
(
byte
)
0xfa
,
(
byte
)
0xce
},
StringUtils
.
convert
Hex
ToBytes
(
"FaCe"
));
try
{
try
{
StringUtils
.
convert
String
ToBytes
(
"120"
);
StringUtils
.
convert
Hex
ToBytes
(
"120"
);
fail
();
fail
();
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
assertKnownException
(
DbException
.
toSQLException
(
e
));
assertKnownException
(
DbException
.
toSQLException
(
e
));
}
}
try
{
try
{
StringUtils
.
convert
String
ToBytes
(
"fast"
);
StringUtils
.
convert
Hex
ToBytes
(
"fast"
);
fail
();
fail
();
}
catch
(
DbException
e
)
{
}
catch
(
DbException
e
)
{
assertKnownException
(
DbException
.
toSQLException
(
e
));
assertKnownException
(
DbException
.
toSQLException
(
e
));
...
...
h2/src/tools/org/h2/dev/fs/FileObjectCrypt.java
浏览文件 @
3b457ffc
...
@@ -44,7 +44,7 @@ public class FileObjectCrypt implements FileObject {
...
@@ -44,7 +44,7 @@ public class FileObjectCrypt implements FileObject {
boolean
newFile
=
file
.
length
()
<
HEADER_LENGTH
+
BLOCK_SIZE
;
boolean
newFile
=
file
.
length
()
<
HEADER_LENGTH
+
BLOCK_SIZE
;
byte
[]
filePasswordHash
;
byte
[]
filePasswordHash
;
if
(
algorithm
.
endsWith
(
"-hash"
))
{
if
(
algorithm
.
endsWith
(
"-hash"
))
{
filePasswordHash
=
StringUtils
.
convert
String
ToBytes
(
password
);
filePasswordHash
=
StringUtils
.
convert
Hex
ToBytes
(
password
);
algorithm
=
algorithm
.
substring
(
0
,
algorithm
.
length
()
-
"-hash"
.
length
());
algorithm
=
algorithm
.
substring
(
0
,
algorithm
.
length
()
-
"-hash"
.
length
());
}
else
{
}
else
{
filePasswordHash
=
SHA256
.
getKeyPasswordHash
(
"file"
,
password
.
toCharArray
());
filePasswordHash
=
SHA256
.
getKeyPasswordHash
(
"file"
,
password
.
toCharArray
());
...
...
h2/src/tools/org/h2/dev/security/SecureKeyStoreBuilder.java
浏览文件 @
3b457ffc
...
@@ -57,14 +57,14 @@ public class SecureKeyStoreBuilder {
...
@@ -57,14 +57,14 @@ public class SecureKeyStoreBuilder {
System
.
out
.
println
(
"KeyFactory keyFactory = KeyFactory.getInstance(\""
+
key
.
getAlgorithm
()
+
"\");"
);
System
.
out
.
println
(
"KeyFactory keyFactory = KeyFactory.getInstance(\""
+
key
.
getAlgorithm
()
+
"\");"
);
System
.
out
.
println
(
"store.load(null, password.toCharArray());"
);
System
.
out
.
println
(
"store.load(null, password.toCharArray());"
);
String
pkFormat
=
key
.
getFormat
();
String
pkFormat
=
key
.
getFormat
();
String
encoded
=
StringUtils
.
convertBytesTo
String
(
key
.
getEncoded
());
String
encoded
=
StringUtils
.
convertBytesTo
Hex
(
key
.
getEncoded
());
System
.
out
.
println
(
pkFormat
+
"EncodedKeySpec keySpec = new "
+
pkFormat
+
"EncodedKeySpec(getBytes(\""
System
.
out
.
println
(
pkFormat
+
"EncodedKeySpec keySpec = new "
+
pkFormat
+
"EncodedKeySpec(getBytes(\""
+
encoded
+
"\"));"
);
+
encoded
+
"\"));"
);
System
.
out
.
println
(
"PrivateKey privateKey = keyFactory.generatePrivate(keySpec);"
);
System
.
out
.
println
(
"PrivateKey privateKey = keyFactory.generatePrivate(keySpec);"
);
System
.
out
.
println
(
"Certificate[] certs = {"
);
System
.
out
.
println
(
"Certificate[] certs = {"
);
for
(
Certificate
cert
:
store
.
getCertificateChain
(
alias
))
{
for
(
Certificate
cert
:
store
.
getCertificateChain
(
alias
))
{
System
.
out
.
println
(
" CertificateFactory.getInstance(\""
+
cert
.
getType
()+
"\")."
);
System
.
out
.
println
(
" CertificateFactory.getInstance(\""
+
cert
.
getType
()+
"\")."
);
String
enc
=
StringUtils
.
convertBytesTo
String
(
cert
.
getEncoded
());
String
enc
=
StringUtils
.
convertBytesTo
Hex
(
cert
.
getEncoded
());
System
.
out
.
println
(
" generateCertificate(new ByteArrayInputStream(getBytes(\""
+
enc
+
"\"))),"
);
System
.
out
.
println
(
" generateCertificate(new ByteArrayInputStream(getBytes(\""
+
enc
+
"\"))),"
);
// PublicKey pubKey = cert.getPublicKey();
// PublicKey pubKey = cert.getPublicKey();
// System.out.println(" pubKey algorithm="+pubKey.getAlgorithm());
// System.out.println(" pubKey algorithm="+pubKey.getAlgorithm());
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论