本文整理汇总了Java中com.digitalpetri.opcua.stack.core.util.SignatureUtil类的典型用法代码示例。如果您正苦于以下问题:Java SignatureUtil类的具体用法?Java SignatureUtil怎么用?Java SignatureUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SignatureUtil类属于com.digitalpetri.opcua.stack.core.util包,在下文中一共展示了SignatureUtil类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getServerSignature
import com.digitalpetri.opcua.stack.core.util.SignatureUtil; //导入依赖的package包/类
private SignatureData getServerSignature(ByteString clientNonce,
ByteString clientCertificate,
SecurityPolicy securityPolicy,
KeyPair keyPair) throws UaException {
if (clientNonce.isNull() || clientCertificate.isNull() || keyPair == null) {
return new SignatureData(null, null);
}
try {
SecurityAlgorithm algorithm = securityPolicy.getAsymmetricSignatureAlgorithm();
byte[] data = Bytes.concat(clientCertificate.bytes(), clientNonce.bytes());
byte[] signature = SignatureUtil.sign(
algorithm,
keyPair.getPrivate(),
ByteBuffer.wrap(data)
);
return new SignatureData(algorithm.getUri(), ByteString.of(signature));
} catch (UaRuntimeException e) {
throw new UaException(StatusCodes.Bad_SecurityChecksFailed);
}
}
示例2: verifyChunk
import com.digitalpetri.opcua.stack.core.util.SignatureUtil; //导入依赖的package包/类
@Override
public void verifyChunk(SecureChannel channel, ByteBuf chunkBuffer) throws UaException {
SecurityAlgorithm securityAlgorithm = channel.getSecurityPolicy().getSymmetricSignatureAlgorithm();
byte[] secretKey = channel.getDecryptionKeys(securitySecrets).getSignatureKey();
int signatureSize = channel.getSymmetricSignatureSize();
ByteBuffer chunkNioBuffer = chunkBuffer.nioBuffer(0, chunkBuffer.writerIndex());
chunkNioBuffer.position(0).limit(chunkBuffer.writerIndex() - signatureSize);
byte[] signature = SignatureUtil.hmac(securityAlgorithm, secretKey, chunkNioBuffer);
byte[] signatureBytes = new byte[signatureSize];
chunkNioBuffer.limit(chunkNioBuffer.position() + signatureSize);
chunkNioBuffer.get(signatureBytes);
if (!Arrays.equals(signature, signatureBytes)) {
throw new UaException(StatusCodes.Bad_SecurityChecksFailed, "could not verify signature");
}
}
示例3: signChunk
import com.digitalpetri.opcua.stack.core.util.SignatureUtil; //导入依赖的package包/类
@Override
public byte[] signChunk(SecureChannel channel, ByteBuffer chunkNioBuffer) throws UaException {
return SignatureUtil.sign(
channel.getSecurityPolicy().getAsymmetricSignatureAlgorithm(),
channel.getKeyPair().getPrivate(),
chunkNioBuffer
);
}