ubuntu base64 encode/decode

本文深入探讨了Base64编码的原理与应用,包括其在MIME协议中的角色,生成和解码的方法,以及在Python中的实现技巧。Base64编码是一种快速、易于识别但不安全的数据转换方式,适合于非关键信息的加密。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

介绍

Base64编码是一种“防君子不防小人”的编码方式。广泛应用于MIME协议,作为电子邮件的传输编码,生成的编码可逆,后一两位可能有“=”,生成的编码都是ascii字符。
优点:速度快,ascii字符,肉眼不可理解
缺点:编码比较长,非常容易被破解,仅适用于加密非关键信息的场合

  • 生成SECRETY_KEY
In [3]: import os

In [5]: import base64

In [6]: s = os.urandom(64)

In [7]: SECRETY_KEY = base64.b64encode(s)

In [8]: print(SECRETY_KEY)
b'VKXV/D7japENU5OcH+40gvd/1RyfBV9OSbll71twKAK1xfmFNgxPscfmvawR8LYQGIrl1mpiT4tBTmdbKVyHqg=='

python3 base64

base64 encoding takes 8-bit binary byte data and encodes it uses only the characters A-Z, a-z, 0-9, +, /* so it can be transmitted over channels that do not preserve all 8-bits of data, such as email.

Hence, it wants a string of 8-bit bytes. You create those in Python 3 with the b’’ syntax.

If you remove the b, it becomes a string. A string is a sequence of Unicode characters. base64 has no idea what to do with Unicode data, it’s not 8-bit. It’s not really any bits, in fact. ?

import base64
def stringToBase64(s):
    return base64.b64encode(s.encode('utf-8'))

def base64ToString(b):
    return base64.b64decode(b).decode('utf-8')
quickly generate a value for Flask.secret_key (or SECRET_KEY):
$ python -c 'import os; print(os.urandom(16))'
b'_5#y2L"F4Q8z\n\xec]/'

base64 - base64 encode/decode data and print to standard output

  • SYNOPSIS
    base64 [OPTION]… [FILE]
  • DISCRIPTION
# man base64
       Base64 encode or decode FILE, or standard input, to standard output.

       With no FILE, or when FILE is -, read standard input.

       Mandatory arguments to long options are mandatory for short options too.

       -d, --decode
              decode data

       -i, --ignore-garbage
              when decoding, ignore non-alphabet characters

       -w, --wrap=COLS
              wrap  encoded  lines  after  COLS  character  (default  76).  Use 0 to disable line
              wrapping

       --help display this help and exit

       --version
              output version information and exit

       The data are encoded as described for the base64 alphabet in RFC 4648.  When decoding, the
       input  may  contain  newlines in addition to the bytes of the formal base64 alphabet.  Use
       --ignore-garbage to attempt to recover from any other non-alphabet bytes  in  the  encoded
       stream.

一、base64加密

格式:base64

从标准输入中读取数据,按Ctrl + D结束输入。将输入的内容编码为base64字符串输出。

格式:echo
“str” | base64
将字符串str + 换行
编码为base64字符串输出。

格式:echo - n
“str” | base64
将字符串str编码为base64字符串输出。

格式:base64
file
从指定的文件file中读取数据,编码为base64字符串输出。

➜  ~ base64 
hello
aGVsbG8K
➜  ~ echo "hello" | base64
aGVsbG8K

二、base64解密

格式:base64 - d
从标准输入中读取已经进行base64编码的内容,解码输出。

格式:base64 - d - i
从标准输入中读取已经进行base64编码的内容,解码输出。加上 - i参数,忽略非字母表字符,比如换行符。

格式:echo
“str” | base64 - d
将base64编码的字符串str + 换行
解码输出。

格式:echo - n
“str” | base64 - d
将base64编码的字符串str解码输出。 注意与上面的差别。

格式:base64 - d
file
从指定的文件file中读取base64编码的内容,解码输出。

➜  ~ base64 -d           
aGVsbG8K
hello
➜  ~ echo "aGVsbG8K" | base64 -d
hello

使用python执行系统命令

import os
os.system(''' echo -n "aGVsbG8K" | base64 -d ''')

ubuntu3个通配符

  • 匹配任意多个任何字符
    ? 匹配一个字符
    [] 匹配中括号里面的一个字符
(base) dwh@dwh:~$ dpkg -l | grep -i nvidia ii libnvidia-cfg1-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA binary OpenGL/GLX configuration library ii libnvidia-common-470 470.256.02-0ubuntu0.20.04.1 all Shared files used by the NVIDIA libraries ii libnvidia-compute-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA libcompute package ii libnvidia-compute-470:i386 470.256.02-0ubuntu0.20.04.1 i386 NVIDIA libcompute package rc libnvidia-compute-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA libcompute package ii libnvidia-decode-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA Video Decoding runtime libraries ii libnvidia-decode-470:i386 470.256.02-0ubuntu0.20.04.1 i386 NVIDIA Video Decoding runtime libraries ii libnvidia-encode-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVENC Video Encoding runtime library ii libnvidia-encode-470:i386 470.256.02-0ubuntu0.20.04.1 i386 NVENC Video Encoding runtime library ii libnvidia-extra-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 Extra libraries for the NVIDIA driver ii libnvidia-fbc1-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA OpenGL-based Framebuffer Capture runtime library ii libnvidia-fbc1-470:i386 470.256.02-0ubuntu0.20.04.1 i386 NVIDIA OpenGL-based Framebuffer Capture runtime library ii libnvidia-gl-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD ii libnvidia-gl-470:i386 470.256.02-0ubuntu0.20.04.1 i386 NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD ii libnvidia-ifr1-470:amd64 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA OpenGL-based Inband Frame Readback runtime library ii libnvidia-ifr1-470:i386 470.256.02-0ubuntu0.20.04.1 i386 NVIDIA OpenGL-based Inband Frame Readback runtime library ii nvidia-compute-utils-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA compute utilities rc nvidia-compute-utils-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA compute utilities ii nvidia-dkms-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA DKMS package rc nvidia-dkms-535 535.183.01-0ubuntu0.20.04.1 amd64 NVIDIA DKMS package ii nvidia-driver-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA driver metapackage ii nvidia-kernel-common-470 470.256.02-0ubuntu0.20.04.1 amd64 Shared files used with the kernel module rc nvidia-kernel-common-535 535.183.01-0ubuntu0.20.04.1 amd64 Shared files used with the kernel module ii nvidia-kernel-source-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA kernel source package ii nvidia-prime 0.8.16~0.20.04.2 all Tools to enable NVIDIA's Prime ii nvidia-settings 470.57.01-0ubuntu0.20.04.3 amd64 Tool for configuring the NVIDIA graphics driver ii nvidia-utils-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA driver support binaries ii screen-resolution-extra 0.18build1 all Extension for the nvidia-settings control panel ii xserver-xorg-video-nvidia-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA binary Xorg driver
04-05
<think>好的,用户让我分析他执行`dpkg -l | grep -i nvidia`后的输出结果。首先,我需要理解这个命令的作用。`dpkg -l`列出所有安装的包,然后用`grep -i nvidia`过滤出包含nvidia的包,不区分大小写。所以用户想查看系统里所有与NVIDIA相关的已安装软件包。 接下来,我需要解析输出中的各个字段。每条记录有五个字段:状态、包名、版本、架构和描述。状态中的"ii"表示已安装,"rc"表示已删除但配置文件还存在。用户提供的输出中有多个包,大部分是470版本的,但也有535版本的标记为rc,这说明用户可能曾经安装过535驱动,但现在被移除了,只留下配置文件。 然后,我需要确定用户当前使用的驱动版本。用户安装了nvidia-driver-470,这是一个元包,说明系统当前使用的是470系列驱动。而535版本显示为rc,可能之前尝试升级或安装过新驱动,但后来被降级或删除了。这时候需要注意是否有残留配置文件可能导致问题,比如冲突或者启动问题。 另外,注意到有i386架构的包,说明用户可能安装了32位的兼容库,这在某些需要32位支持的应用程序中是需要的,比如某些游戏或旧版软件。同时,nvidia-prime的存在说明用户可能在双显卡笔记本上使用NVIDIA Optimus技术,切换显卡使用。 用户可能想知道这些信息背后的含义,或者遇到驱动相关的问题,比如图形显示问题、驱动冲突等。可能需要检查是否有残留的旧版驱动影响当前系统,或者是否需要清理rc状态的包。此外,用户可能关心如何升级到更新的驱动版本,或者确认当前驱动是否正常。 最后,我应该建议用户如果有问题,可以进一步检查驱动状态,使用命令如`nvidia-smi`验证驱动是否正常运行,或者考虑清理rc状态的包,使用`sudo apt purge`来彻底移除旧驱动配置文件,确保系统稳定。</think>你提供的输出内容展示了系统中安装的 NVIDIA 相关软件包信息。以下是逐步解析: --- ### **一、命令解析** `(base) dwh@dwh:~$ dpkg -l | grep -i nvidia` - **作用**: 列出所有已安装的 NVIDIA 相关软件包 - **输出字段说明**: - **状态标记**(第1列): - `ii`: 表示软件包已正确安装 - `rc`: 表示软件包已被卸载,但配置文件仍残留 --- ### **二、核心组件分析** #### 1. **当前生效的驱动版本:470 系列** - **主驱动包**: ```plaintext ii nvidia-driver-470 470.256.02-0ubuntu0.20.04.1 amd64 NVIDIA driver metapackage ``` - 这是驱动元包,表示系统正在使用 **470.256.02** 版本驱动 - **关键依赖组件**: - `nvidia-dkms-470`: 动态内核模块支持 - `nvidia-kernel-source-470`: 内核源码 - `nvidia-utils-470`: 驱动程序工具集 #### 2. **残留的旧版本组件:535 系列** - **标记为 `rc` 的包**: ```plaintext rc libnvidia-compute-535:amd64 535.183.01-0ubuntu0.20.04.1 amd64 rc nvidia-dkms-535 535.183.01-0ubuntu0.20.04.1 amd64 ``` - 表明系统曾安装过 535 版本驱动,但已被卸载(仅残留配置文件) --- ### **三、其他重要组件** 1. **多架构支持**: - 包含 `amd64` 和 `i386` 架构的库(如 `libnvidia-gl-470:i386`) - 用途:支持 32 位应用程序调用 NVIDIA 功能 2. **图形相关库**: - `libnvidia-gl-470`: OpenGL/Vulkan 支持 - `xserver-xorg-video-nvidia-470`: Xorg 显示驱动 3. **工具与实用程序**: - `nvidia-settings`: 显卡配置 GUI 工具 - `nvidia-prime`: 双显卡切换工具(适用于笔记本) --- ### **四、潜在问题排查** 1. **残留配置文件**: - 状态为 `rc` 的包可能引发冲突,可通过以下命令清理: ```bash sudo apt purge $(dpkg -l | grep ^rc | grep nvidia | awk '{print $2}') ``` 2. **驱动版本管理**: - 检查当前实际加载的驱动版本: ```bash nvidia-smi # 查看驱动版本与 GPU 状态 ``` --- ### **五、总结** - **当前生效驱动**: **470.256.02** 系列 - **遗留问题**: 存在 535 版本的残留配置文件 - **建议操作**: 如需升级或降级驱动,请使用 `apt` 命令指定版本,并清理残留文件 如果需要进一步操作指导,请补充具体使用场景(如深度学习、游戏等)或问题现象。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值