當前位置: 首頁>>代碼示例>>Java>>正文


Java SignatureUtil類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:digitalpetri,項目名稱:ua-server-sdk,代碼行數:26,代碼來源:SessionManager.java

示例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");
    }
}
 
開發者ID:digitalpetri,項目名稱:opc-ua-stack,代碼行數:20,代碼來源:ChunkDecoder.java

示例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
    );
}
 
開發者ID:digitalpetri,項目名稱:opc-ua-stack,代碼行數:9,代碼來源:ChunkEncoder.java


注:本文中的com.digitalpetri.opcua.stack.core.util.SignatureUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。