https://github.com/janmarvin/msoc
https://github.com/janmarvin/msoc
encryption-decryption ooxml r r-package
Last synced: 5 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/janmarvin/msoc
- Owner: JanMarvin
- License: other
- Created: 2023-07-29T08:58:48.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-21T23:07:51.000Z (6 months ago)
- Last Synced: 2025-04-22T00:20:03.495Z (6 months ago)
- Topics: encryption-decryption, ooxml, r, r-package
- Language: C++
- Homepage: https://janmarvin.github.io/msoc/
- Size: 7.79 MB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```# msoc
[](https://github.com/JanMarvin/msoc/actions)
[](https://janmarvin.r-universe.dev/msoc)This R package provides the cryptographic library [msoc](https://github.com/herumi/msoffice) and allows encrypting and decrypting office open xml files with R.
## Installation
You can install the development version of `msoc` from
[GitHub](https://github.com/) with:``` r
# install.packages("remotes")
remotes::install_github("JanMarvin/msoc")
```Or from [r-universe](https://r-universe.dev/) with:
``` r
# Enable repository from janmarvin
options(repos = c(
janmarvin = 'https://janmarvin.r-universe.dev',
CRAN = 'https://cloud.r-project.org'))
# Download and install msoc in R
install.packages('msoc')
```## Introduction
A word of warning. I have no background in cryptography and I am somewhat unable
to maintain the bundled msoc library. Assume that I only made it work and if it
ever breaks, you are on your own. Due to these reasons the package will never
be released to CRAN either.Before you encrypt a file, you should memorize the password. If you forget the
password, there is no way to recover the contents of the file.Prior to release 0.2 password encoding was not extensively tested. And possibly
broken. If a file with a non ASCII password does not open with spreadsheet
software it should still be possible to decrypt the file with a `msoc` release
< 0.2.
Support for non ASCII characters is included since 0.2, but even spreadsheet
software warns that passwords with non ASCII characters might not open with
some spreadsheet software. Therefore it is recommended to check that files
encoded this way, can be opened in spreadsheet software and otherwise fall back
to a pure ASCII password.```{r}
library(msoc)
file <- system.file("extdata", "Untitled1.xlsx", package = "msoc")# out is an encrypted file and you will
# be unable to open it without the password
out <- encrypt(file, pass = "msoc")# out is an decrypted file and readable
# without the password
out <- decrypt(out, pass = "msoc")
```## An example with [`openxlsx2`](https://github.com/JanMarvin/openxlsx2)
```{r}
library(openxlsx2)
library(msoc)xlsx <- temp_xlsx()
# let us write some worksheet
wb_workbook()$add_worksheet()$add_data(x = mtcars)$save(xlsx)# now we can encrypt it
encrypt(xlsx, xlsx, pass = "msoc")# the file is encrypted, we can not read it
try(wb <- wb_load(xlsx))# we have to decrypt it first
decrypt(xlsx, xlsx, pass = "msoc")# now we can load it again
wb_load(xlsx)$to_df() %>% head()
```## License
This package is licensed under the BSD 3-Clause license and is based on
[`msoffice`](https://github.com/herumi/msoffice) (by Cybozu Labs, Inc;
COPYRIGHT 2007-2015 and Shigeo Mitsunari;COPYRIGHT 2015-2023) and [`cybozulib`](https://github.com/herumi/cybozulib) (by Cybozu Labs, Inc;
COPYRIGHT 2007-2012 and Shigeo Mitsunari; COPYRIGHT 2012-2023). Both release
under the BSD 3-Clause License.