public ECKey decrypt ( KeyCrypter keyCrypter , KeyParameter aesKey ) throws KeyCrypterException { checkNotNull ( keyCrypter ) ; // Check that the keyCrypter matches the one used to encrypt the keys, if set. if ( this . keyCrypter != null && ! this . keyCrypter . equals ( keyCrypter ) ) throw new KeyCrypterException ( "The keyCrypter being used to decrypt the key is different to the one that was used to encrypt it" ) ; checkState ( encryptedPrivateKey != null , "This key is not encrypted" ) ; byte [ ] unencryptedPrivateKey = keyCrypter . decrypt ( encryptedPrivateKey , aesKey ) ; if ( unencryptedPrivateKey . length != 32 ) throw new KeyCrypterException . InvalidCipherText ( "Decrypted key must be 32 bytes long, but is " + unencryptedPrivateKey . length ) ; ECKey key = ECKey . fromPrivate ( unencryptedPrivateKey ) ; if ( ! isCompressed ( ) ) key = key . decompress ( ) ; if ( ! Arrays . equals ( key . getPubKey ( ) , getPubKey ( ) ) ) throw new KeyCrypterException ( "Provided AES key is wrong" ) ; key . setCreationTimeSeconds ( creationTimeSeconds ) ; return key ; }
Create a decrypted private key with the keyCrypter and AES key supplied . Note that if the aesKey is wrong this has some chance of throwing KeyCrypterException due to the corrupted padding that will result but it can also just yield a garbage key .