private BigInteger findOrDeriveEncryptedPrivateKey ( KeyCrypter keyCrypter , KeyParameter aesKey ) { if ( encryptedPrivateKey != null ) { byte [ ] decryptedKey = keyCrypter . decrypt ( encryptedPrivateKey , aesKey ) ; if ( decryptedKey . length != 32 ) throw new KeyCrypterException . InvalidCipherText ( "Decrypted key must be 32 bytes long, but is " + decryptedKey . length ) ; return new BigInteger ( 1 , decryptedKey ) ; } // Otherwise we don't have it, but maybe we can figure it out from our parents. Walk up the tree looking for // the first key that has some encrypted private key data. DeterministicKey cursor = parent ; while ( cursor != null ) { if ( cursor . encryptedPrivateKey != null ) break ; cursor = cursor . parent ; } if ( cursor == null ) throw new KeyCrypterException ( "Neither this key nor its parents have an encrypted private key" ) ; byte [ ] parentalPrivateKeyBytes = keyCrypter . decrypt ( cursor . encryptedPrivateKey , aesKey ) ; if ( parentalPrivateKeyBytes . length != 32 ) throw new KeyCrypterException . InvalidCipherText ( "Decrypted key must be 32 bytes long, but is " + parentalPrivateKeyBytes . length ) ; return derivePrivateKeyDownwards ( cursor , parentalPrivateKeyBytes ) ; }
to decrypt and re - derive .