Пример #1
0
            /// <summary>
            /// Create a component of type ImplicitSha256DigestComponent, so that
            /// isImplicitSha256Digest() is true.
            /// </summary>
            ///
            /// <param name="digest">The SHA-256 digest value.</param>
            /// <returns>The new Component.</returns>
            /// <exception cref="EncodingException">If the digest length is not 32 bytes.</exception>
            public static Name.Component fromImplicitSha256Digest(Blob digest)
            {
                if (digest.size() != 32)
                    throw new EncodingException(
                            "Name.Component.fromImplicitSha256Digest: The digest length must be 32 bytes");

                Name.Component  result = new Name.Component (digest);
                result.type_ = net.named_data.jndn.Name.Component.ComponentType.IMPLICIT_SHA256_DIGEST;
                return result;
            }
Пример #2
0
        /// <summary>
        /// Decrypt dKeyData.
        /// </summary>
        ///
        /// <param name="dKeyData">The D-KEY data packet.</param>
        /// <param name="onPlainText_0"></param>
        /// <param name="onError_1">This calls onError.onError(errorCode, message) for an error.</param>
        internal void decryptDKey(Data dKeyData, Consumer.OnPlainText  onPlainText_0,
				net.named_data.jndn.encrypt.EncryptError.OnError  onError_1)
        {
            // Get the encrypted content.
            Blob dataContent = dKeyData.getContent();

            // Process the nonce.
            // dataContent is a sequence of the two EncryptedContent.
            EncryptedContent encryptedNonce = new EncryptedContent();
            try {
                encryptedNonce.wireDecode(dataContent);
            } catch (EncodingException ex) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
                            ex.Message);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception);
                }
                return;
            }
            Name consumerKeyName = encryptedNonce.getKeyLocator().getKeyName();

            // Get consumer decryption key.
            Blob consumerKeyBlob;
            try {
                consumerKeyBlob = getDecryptionKey(consumerKeyName);
            } catch (ConsumerDb.Error ex_2) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.NoDecryptKey,
                            "Database error: " + ex_2.Message);
                } catch (Exception exception_3) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_3);
                }
                return;
            }
            if (consumerKeyBlob.size() == 0) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.NoDecryptKey,
                            "The desired consumer decryption key in not in the database");
                } catch (Exception exception_4) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", exception_4);
                }
                return;
            }

            // Process the D-KEY.
            // Use the size of encryptedNonce to find the start of encryptedPayload.
            ByteBuffer encryptedPayloadBuffer = dataContent.buf().duplicate();
            encryptedPayloadBuffer.position(encryptedNonce.wireEncode().size());
            Blob encryptedPayloadBlob_5 = new Blob(encryptedPayloadBuffer,
                    false);
            if (encryptedPayloadBlob_5.size() == 0) {
                try {
                    onError_1.onError(net.named_data.jndn.encrypt.EncryptError.ErrorCode.InvalidEncryptedFormat,
                            "The data packet does not satisfy the D-KEY packet format");
                } catch (Exception ex_6) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onError", ex_6);
                }
                return;
            }

            // Decrypt the D-KEY.
            Consumer.OnPlainText  callerOnPlainText_7 = onPlainText_0;
            decrypt(encryptedNonce, consumerKeyBlob, new Consumer.Anonymous_C0 (callerOnPlainText_7, encryptedPayloadBlob_5, onError_1), onError_1);
        }