diff --git a/pre_commit_hooks/detect_private_key.py b/pre_commit_hooks/detect_private_key.py
index 215ad56..782b680 100644
--- a/pre_commit_hooks/detect_private_key.py
+++ b/pre_commit_hooks/detect_private_key.py
@@ -1,7 +1,6 @@
 from __future__ import print_function
 
 import argparse
-import io
 import sys
 
 
@@ -13,12 +12,11 @@ def detect_private_key(argv=None):
     private_key_files = []
 
     for filename in args.filenames:
-        with io.open(filename, 'r') as f:
-            content = f.read()
-            if 'BEGIN RSA PRIVATE KEY' in content:
-                private_key_files.append(content)
-            if 'BEGIN DSA PRIVATE KEY' in content:
-                private_key_files.append(content)
+        content = open(filename, 'rb').read()
+        if b'BEGIN RSA PRIVATE KEY' in content:
+            private_key_files.append(content)
+        if b'BEGIN DSA PRIVATE KEY' in content:
+            private_key_files.append(content)
 
     if private_key_files:
         for private_key_file in private_key_files:

detect-private-key hook appears to crash with images in the directory
Just added some images and a resources.qrc file to my PyQt4 project and got this error out of it. Is it because it tries to decode images as text?

```
Detect Private Key.......................................................Failed
hookid: detect-private-key

Traceback (most recent call last):

  File "C:\cygwin64\home\builder\.pre-commit\repo7jrxo4\py_env-default\Scripts\detect-private-key-script.py", line 9, in \<module\>

    load_entry_point('pre-commit-hooks==0.4.2', 'console_scripts', 'detect-private-key')()

  File "C:\cygwin64\home\builder\.pre-commit\repo7jrxo4\py_env-default\lib\site-packages\pre_commit_hooks\detect_private_key.py", line 17, in detect_private_key

    content = f.read()

  File "C:\cygwin64\home\builder\.pre-commit\repo7jrxo4\py_env-default\lib\encodings\cp1252.py", line 23, in decode

    return codecs.charmap_decode(input,self.errors,decoding_table)[0]

UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 44: character maps to \<undefined\>
```
diff --git a/tests/detect_private_key_test.py b/tests/detect_private_key_test.py
index 6d2e627..c912624 100644
--- a/tests/detect_private_key_test.py
+++ b/tests/detect_private_key_test.py
@@ -10,6 +10,8 @@ TESTS = (
     (b'-----BEGIN DSA PRIVATE KEY-----', 1),
     (b'ssh-rsa DATA', 0),
     (b'ssh-dsa DATA', 0),
+    # Some arbitrary binary data
+    (b'\xa2\xf1\x93\x12', 0),
 )
 
 

pip install -e .
parse_log_pytest
pytest
pytest
3.9
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
autopep8==2.3.2
exceptiongroup @ file:///croot/exceptiongroup_1706031385326/work
flake8==7.2.0
iniconfig @ file:///home/linux1/recipes/ci/iniconfig_1610983019677/work
mccabe==0.7.0
packaging @ file:///croot/packaging_1734472117206/work
pluggy @ file:///croot/pluggy_1733169602837/work
-e git+https://github.com/pre-commit/pre-commit-hooks.git@6077f2fefb542fa4ffd3e2f305d1986645110645#egg=pre_commit_hooks
pycodestyle==2.13.0
pyflakes==3.3.1
pytest @ file:///croot/pytest_1738938843180/work
PyYAML==6.0.2
simplejson==3.20.1
tomli @ file:///opt/conda/conda-bld/tomli_1657175507142/work

name: pre-commit-hooks
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - exceptiongroup=1.2.0=py39h06a4308_0
  - iniconfig=1.1.1=pyhd3eb1b0_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.4.4=h6a678d5_1
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=3.0.16=h5eee18b_0
  - packaging=24.2=py39h06a4308_0
  - pip=25.0=py39h06a4308_0
  - pluggy=1.5.0=py39h06a4308_0
  - pytest=8.3.4=py39h06a4308_0
  - python=3.9.21=he870216_1
  - readline=8.2=h5eee18b_0
  - setuptools=75.8.0=py39h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - tomli=2.0.1=py39h06a4308_0
  - tzdata=2025a=h04d1e81_0
  - wheel=0.45.1=py39h06a4308_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - argparse==1.4.0
      - autopep8==2.3.2
      - flake8==7.2.0
      - mccabe==0.7.0
      - pycodestyle==2.13.0
      - pyflakes==3.3.1
      - pyyaml==6.0.2
      - simplejson==3.20.1
prefix: /opt/conda/envs/pre-commit-hooks

tests/detect_private_key_test.py::test_detect_private_key[\xa2\xf1\x93\x12-0]
tests/detect_private_key_test.py::test_detect_private_key[-----BEGIN tests/detect_private_key_test.py::test_detect_private_key[ssh-rsa tests/detect_private_key_test.py::test_detect_private_key[ssh-dsa
pre_commit_hooks/detect_private_key.py
pre_commit_hooks/detect_private_key.py