mil.dod.th.ose.remote/src/mil/dod/th/ose/remote/encryption/EncryptMessageServiceImpl.java
@Override
    public TerraHarvestPayload decryptRemoteMessage(final TerraHarvestMessage message) 
            throws InvalidProtocolBufferException, InvalidKeySignatureException  
    {
        if (message.getEncryptType().equals(EncryptType.NONE))
        {
            return TerraHarvestPayload.parseFrom(message.getTerraHarvestPayload());
        }
        final byte[] payload = message.getTerraHarvestPayload().toByteArray();
        final EncryptInfo encryptInfo = message.getEncryptInfo();
        final int localSystemId = message.getDestId();
        final int remoteSystemId = message.getSourceId();
        //parse the initialization vector from The TerraHarvestMessage
        final IvParameterSpec ivBytes_New = new IvParameterSpec(encryptInfo.getInitializationVector().toByteArray());
        
        //we will verify the signature using sender public key and the ephemeral key received with
        //the message and the ephemeral signature itself
        final DSADigestSigner dsaSigner1 = new DSADigestSigner(new ECDSASigner(), new SHA256Digest()); 
        dsaSigner1.init(false, getRemotePublicKey(remoteSystemId));
        final byte[] ephemeralKeyTemp = encryptInfo.getEphemeralKey().toByteArray();
        dsaSigner1.update(ephemeralKeyTemp, 0, ephemeralKeyTemp.length);
        final boolean sigOK = dsaSigner1.verifySignature(encryptInfo.getEphemeralKeySignature().toByteArray());
        
        if (sigOK)
        {
            m_Logging.info("Message key signature verification passed");
        }
        else
        {
            throw new InvalidKeySignatureException("Message key signature verification failed");
        }
        //generate the shared key 
        //first get the ephemeral public key from the message and source private key
        final ECPoint qPoint = EncryptionUtility.CURVEPARAMS.getCurve().
                                           decodePoint(ephemeralKeyTemp);
        final ECPublicKeyParameters ephemeralPublicKey = new ECPublicKeyParameters(
                                                            qPoint, EncryptionUtility.CURVEPARAMS);
        //local and remote system id gets flipped for decrypt.   
        final byte[] sharedKeyBytesDecrypt = EncryptionUtility.sharedEcdhKeyCreate(getPrivateStaticKey(),
            ephemeralPublicKey, remoteSystemId, localSystemId);
       

        final Key key = new SecretKeySpec(sharedKeyBytesDecrypt, ENCRYPT_ALGORITHM_AES);
        
        final byte[] decrypt;
        //Create a CIpher object to perform the decryption
        try
        {
            m_Output.init(Cipher.DECRYPT_MODE, key, ivBytes_New);
            decrypt = m_Output.doFinal(payload);
        }
        catch (final InvalidKeyException e) 
        {
            throw new IllegalArgumentException("Key returned by KDF does not meet specification", e);
        } 
        catch (final InvalidAlgorithmParameterException e)
        {
            throw new IllegalArgumentException("Inappropriate Algorithm parameters", e);
        }
        catch (final IllegalBlockSizeException e)
        {
            throw new IllegalArgumentException("Data and block size are not aligned", e);
        }
        catch (final BadPaddingException e)
        {
            throw new IllegalArgumentException("Data is not padded appropriately for the padding mechanism", e);
        }

        return TerraHarvestPayload.parseFrom(decrypt);
    }
/**
     * Decrypt the payload inside the TerraHarvestMessage.
     * 
     * @return
     *     returns a decrypted (original) payload
     * @param message
     *        TerraHarvestMessage contains the encrypted payload bytes 
     * @throws InvalidProtocolBufferException
     *        thrown when a protocol message being parsed is invalid
     * @throws InvalidKeySignatureException 
     *        thrown when key signatures can not be verified during decryption
     */
Decrypt the payload inside the TerraHarvestMessage.

@return
returns a decrypted (original) payload
@param message
TerraHarvestMessage contains the encrypted payload bytes
@throws InvalidProtocolBufferException
thrown when a protocol message being parsed is invalid
@throws InvalidKeySignatureException
thrown when key signatures can not be verified during decryption
Decrypt the payload inside the TerraHarvestMessage . @return returns a decrypted ( original ) payload @param message TerraHarvestMessage contains the encrypted payload bytes @throws InvalidProtocolBufferException thrown when a protocol message being parsed is invalid @throws InvalidKeySignatureException thrown when key signatures can not be verified during decryption
@Override
    public TerraHarvestPayload decryptRemoteMessage(final TerraHarvestMessage message) 
            throws InvalidProtocolBufferException, InvalidKeySignatureException  
    {
        if (message.getEncryptType().equals(EncryptType.NONE))
        {
            return TerraHarvestPayload.parseFrom(message.getTerraHarvestPayload());
        }
        final byte[] payload = message.getTerraHarvestPayload().toByteArray();
        final EncryptInfo encryptInfo = message.getEncryptInfo();
        final int localSystemId = message.getDestId();
        final int remoteSystemId = message.getSourceId();
        final IvParameterSpec ivBytes_New = new IvParameterSpec(encryptInfo.getInitializationVector().toByteArray());
        final DSADigestSigner dsaSigner1 = new DSADigestSigner(new ECDSASigner(), new SHA256Digest()); 
        dsaSigner1.init(false, getRemotePublicKey(remoteSystemId));
        final byte[] ephemeralKeyTemp = encryptInfo.getEphemeralKey().toByteArray();
        dsaSigner1.update(ephemeralKeyTemp, 0, ephemeralKeyTemp.length);
        final boolean sigOK = dsaSigner1.verifySignature(encryptInfo.getEphemeralKeySignature().toByteArray());
        if (sigOK)
        {
            m_Logging.info("Message key signature verification passed");
        }
        else
        {
            throw new InvalidKeySignatureException("Message key signature verification failed");
        }
        final ECPoint qPoint = EncryptionUtility.CURVEPARAMS.getCurve().
                                           decodePoint(ephemeralKeyTemp);
        final ECPublicKeyParameters ephemeralPublicKey = new ECPublicKeyParameters(
                                                            qPoint, EncryptionUtility.CURVEPARAMS);
        final byte[] sharedKeyBytesDecrypt = EncryptionUtility.sharedEcdhKeyCreate(getPrivateStaticKey(),
            ephemeralPublicKey, remoteSystemId, localSystemId);
        final Key key = new SecretKeySpec(sharedKeyBytesDecrypt, ENCRYPT_ALGORITHM_AES);
        final byte[] decrypt;
        try
        {
            m_Output.init(Cipher.DECRYPT_MODE, key, ivBytes_New);
            decrypt = m_Output.doFinal(payload);
        }
        catch (final InvalidKeyException e) 
        {
            throw new IllegalArgumentException("Key returned by KDF does not meet specification", e);
        } 
        catch (final InvalidAlgorithmParameterException e)
        {
            throw new IllegalArgumentException("Inappropriate Algorithm parameters", e);
        }
        catch (final IllegalBlockSizeException e)
        {
            throw new IllegalArgumentException("Data and block size are not aligned", e);
        }
        catch (final BadPaddingException e)
        {
            throw new IllegalArgumentException("Data is not padded appropriately for the padding mechanism", e);
        }
        return TerraHarvestPayload.parseFrom(decrypt);
    }
@ Override public TerraHarvestPayload decryptRemoteMessage ( final TerraHarvestMessage message ) throws InvalidProtocolBufferException , InvalidKeySignatureException { if ( message . getEncryptType ( ) . equals ( EncryptType . NONE ) ) { return TerraHarvestPayload . parseFrom ( message . getTerraHarvestPayload ( ) ) ; } final byte [ ] payload = message . getTerraHarvestPayload ( ) . toByteArray ( ) ; final EncryptInfo encryptInfo = message . getEncryptInfo ( ) ; final int localSystemId = message . getDestId ( ) ; final int remoteSystemId = message . getSourceId ( ) ; final IvParameterSpec ivBytes_New = new IvParameterSpec ( encryptInfo . getInitializationVector ( ) . toByteArray ( ) ) ; final DSADigestSigner dsaSigner1 = new DSADigestSigner ( new ECDSASigner ( ) , new SHA256Digest ( ) ) ; dsaSigner1 . init ( false , getRemotePublicKey ( remoteSystemId ) ) ; final byte [ ] ephemeralKeyTemp = encryptInfo . getEphemeralKey ( ) . toByteArray ( ) ; dsaSigner1 . update ( ephemeralKeyTemp , 0 , ephemeralKeyTemp . length ) ; final boolean sigOK = dsaSigner1 . verifySignature ( encryptInfo . getEphemeralKeySignature ( ) . toByteArray ( ) ) ; if ( sigOK ) { m_Logging . info ( "Message key signature verification passed" ) ; } else { throw new InvalidKeySignatureException ( "Message key signature verification failed" ) ; } final ECPoint qPoint = EncryptionUtility . CURVEPARAMS . getCurve ( ) . decodePoint ( ephemeralKeyTemp ) ; final ECPublicKeyParameters ephemeralPublicKey = new ECPublicKeyParameters ( qPoint , EncryptionUtility . CURVEPARAMS ) ; final byte [ ] sharedKeyBytesDecrypt = EncryptionUtility . sharedEcdhKeyCreate ( getPrivateStaticKey ( ) , ephemeralPublicKey , remoteSystemId , localSystemId ) ; final Key key = new SecretKeySpec ( sharedKeyBytesDecrypt , ENCRYPT_ALGORITHM_AES ) ; final byte [ ] decrypt ; try { m_Output . init ( Cipher . DECRYPT_MODE , key , ivBytes_New ) ; decrypt = m_Output . doFinal ( payload ) ; } catch ( final InvalidKeyException e ) { throw new IllegalArgumentException ( "Key returned by KDF does not meet specification" , e ) ; } catch ( final InvalidAlgorithmParameterException e ) { throw new IllegalArgumentException ( "Inappropriate Algorithm parameters" , e ) ; } catch ( final IllegalBlockSizeException e ) { throw new IllegalArgumentException ( "Data and block size are not aligned" , e ) ; } catch ( final BadPaddingException e ) { throw new IllegalArgumentException ( "Data is not padded appropriately for the padding mechanism" , e ) ; } return TerraHarvestPayload . parseFrom ( decrypt ) ; }
Decrypt the payload inside the TerraHarvestMessage.
Decrypt the payload inside the TerraHarvestMessage .
//parse the initialization vector from The TerraHarvestMessage //we will verify the signature using sender public key and the ephemeral key received with //the message and the ephemeral signature itself //generate the shared key  //first get the ephemeral public key from the message and source private key //local and remote system id gets flipped for decrypt.    //Create a CIpher object to perform the decryption