[20200103]GUID转换GUID_BASE64.txt

--//最近在做一个项目优化,里面大量使用uuid.优缺点在链接:http://blog.itpub.net.x.y265/viewspace-2670513/=>[20191225]主键使
--//用uuid优缺点.txt 有相关讨论.我自己的观点不要滥用,或者讲到处都用,合理使用才是比较正确的选择.

--//昨天看12c相关书籍,发现oracle给每个PDB设置唯一GUID.我查看视图V$CONTAINERs,发现有1个字段GUID_BASE64,很明显这个从guid转
--//换过来,自己想知道这个转换如何实现的?

1.环境:
SYS@192.168.x.y:1521/orclcdb> select banner from v$version;
BANNER
----------------------------------------------------------------------
Oracle Database 18c Enterprise Edition Release 18.0.0.0.0 - Production

SYS@192.168.x.y:1521/orclcdb> select sys_guid() from dual ;
SYS_GUID()
--------------------------------
9B25CF226E3E36A5E0558253DD747177

SYS@192.168.x.y:1521/orclcdb>  select CON_ID,DBID,CON_UID,NAME,GUID,GUID_BASE64 from V$CONTAINERs;
CON_ID       DBID    CON_UID NAME     GUID                             GUID_BASE64
------ ---------- ---------- -------- -------------------------------- ------------------------
     1 2756091850          1 CDB$ROOT 64A52F53A7683286E053CDA9E80AED76 ZKUvU6doMobgU82p6Artdg==
     2 1474312904 1474312904 PDB$SEED 742DCFA2CE044FDEE0558253DD747177 dC3Pos4ET97gVYJT3XRxdw==
     3  115310104  115310104 ORCL     74A69DC145F5662BE0558253DD747177 dKadwUX1ZivgVYJT3XRxdw==

--//注意看sys_guid()后面16位E0558253DD747177,居然没有变化,不知道为什么.
--//GUID_BASE64后面2位是字符'==',不可能3个正好都是==,一定是用来填充保持字符串长度24.

2.首先我必须确定GUID_BASE64的编码:
--//base64,我的理解就是64进制,确定编码很重要,最容易联想到的rowid编码也是64进制,是否其编码与它一样.
--//我检索发现如下链接:
https://docs.oracle.com/cd/E18150_01/javadocs/DevelopmentKit/com/stc/connector/framework/util/Base64.html

--//内容如下:
            Table 1: The Base64 Alphabet
Value Encoding  Value Encoding  Value Encoding  Value Encoding
   0 A            17 R            34 i            51 z
   1 B            18 S            35 j            52 0
   2 C            19 T            36 k            53 1
   3 D            20 U            37 l            54 2
   4 E            21 V            38 m            55 3
   5 F            22 W            39 n            56 4
   6 G            23 X            40 o            57 5
   7 H            24 Y            41 p            58 6
   8 I            25 Z            42 q            59 7
   9 J            26 a            43 r            60 8
  10 K            27 b            44 s            61 9
  11 L            28 c            45 t            62 +
  12 M            29 d            46 u            63 /
  13 N            30 e            47 v
  14 O            31 f            48 w         (pad) =
  15 P            32 g            49 x
  16 Q            33 h            50 y
--//= 作为pad与看到结果一样.

The encoded output stream must be represented in lines of no more than 76 characters each. All line breaks or other
characters no found in Table 1 must be ignored by decoding software. In base64 data, characters other than those in
Table 1, line breaks, and other white space probably indicate a transmission error, about which a warning message or
even a message rejection might be appropriate under some circumstances.

编码的输出流必须以不超过76个字符的行表示。所有行打断或其他解码软件必须忽略表1中没有找到的字符。在base64数据中,除了那些
表1、断行和其他空白可能表示传输错误,有关该错误的警告消息或在某些情况下,即使是拒绝信息也可能是合适的。

Special processing is performed if fewer than 24 bits are available at the end of the data being encoded. A full
encoding quantum is always completed at the end of a body. When fewer than 24 input bits are available in an input
group, zero bits are added (on the right) to form an integral number of 6-bit groups. Padding at the end of the data is
performed using the "=" character. Since all base64 input is an integral number of octets, only the following cases can
arise: (1) the final quantum of encoding input is an integral multiple of 24 bits; here, the final unit of encoded
output will be an integral multiple of 4 characters with no "=" padding, (2) the final quantum of encoding input is
exactly 8 bits; here, the final unit of encoded output will be two characters followed by two "=" padding characters, or
(3) the final quantum of encoding input is exactly 16 bits; here, the final unit of encoded output will be three
characters followed by one "=" padding character.

如果在被编码数据的末尾有少于24位可用,则执行特殊处理。一个完整的编码量子总是在物体的末端完成。当一个输入中可用的输入位少
于24位时组,零位被添加(在右边)形成一个6位组的整数。数据末尾的填充物是使用"="字符执行。由于所有base64输入都是八进制的整数
,所以只有以下情况才能产生:
(1)编码输入的最终量子是24位的整数倍;这里是编码的最终单位输出将是4个字符的整数倍,没有"="填充.
(2)编码输入的最终数量是8位,编码输出的最终单位将是两个字符,后面跟着两个"="填充字符,或者
(3)编码输入的最终量子正好是16位;这里,编码输出的最终单位是三位字符后面跟着一个"="填充字符。

Because it is used only for padding at the end of the data, the occurrence of any "=" characters may be taken as
evidence that the end of the data has been reached (without truncation in transit). No such assurance is possible,
however, when the number of octets transmitted was a multiple of three and no "=" characters are present.

因为它只用于数据末尾的填充,所以任何"="字符的出现都可以作为数据结束的证据已经到达(在运输过程中没有截断)。不可能有这样的
保证,然而,当传输的八位数是三个的倍数,并且没有"="字符存在时。

Any characters outside of the base64 alphabet are to be ignored in base64-encoded data.

在base64编码的数据中,base64字母表之外的任何字符都将被忽略。

Care must be taken to use the proper octets for line breaks if base64 encoding is applied directly to text material that
has not been converted to canonical form. In particular, text line breaks must be converted into CRLF sequences prior to
base64 encoding. The important thing to note is that this may be done directly by the encoder rather than in a prior
canonicalization step in some implementations.

如果base64编码直接应用于尚未转换为规范形式。特别是,文本换行必须先转换成CRLF序列。base64编码。重要的是要注意的是,这可能
是由编码器直接完成的,而不是在以前完成的。规范化步骤在一些实现中。

NOTE: There is no need to worry about quoting potential boundary delimiters within base64-encoded bodies within
multipart entities because no hyphen characters are used in the base64 encoding.

--//注:翻译我使用金山词霸,可能存在一些瑕疵...
--//这样base64的编码可以确定.A_Z a-z 0-9 +/

3.我写一个测试脚本:
 $ cat 64base.sh
#! /bin/bash
v2=$1
BASE64=($( echo {A..Z} {a..z} {0..9} + / ))

res=''
for i in $(echo "obase=64;ibase=16; $v2" | bc| tr -d '\\\r\n')
do
    res=${res}${BASE64[$(( 10#$i ))]}
done

echo $res

$ ./64base.sh 74A69DC145F5662BE0558253DD747177
B0pp3BRfVmK+BVglPddHF3

--//完全对不上.我再仔细看链接https://docs.oracle.com/cd/E18150_01/javadocs/DevelopmentKit/com/stc/connector/framework/util/Base64.html
--//说明.
When fewer than 24 input bits are available in an input group, zero bits are added (on the right) to form an integral
number of 6-bit groups. Padding at the end of the data is performed using the "=" character.

--//有1个非常明显的提示 "zero bits are added (on the right) to form an integral number of 6-bit groups".
--//guid的显示74A69DC145F5662BE0558253DD747177,占32字符.32*4 = 128 bits.
--//base64 相当于2^6,也就是6 bits表示1个64进制字符.
--//128/6 = 21.333,明显无法整除,这样结尾要补上1个0(占4bits).
--//(128+4)/6 = 22,这样正好整除.
--//补上1个0再计算如下:

$ ./64base.sh 74A69DC145F5662BE0558253DD7471770
dKadwUX1ZivgVYJT3XRxdw

--//^_^正好对上.可以验证看看.

$ echo 64A52F53A7683286E053CDA9E80AED760 742DCFA2CE044FDEE0558253DD7471770 74A69DC145F5662BE0558253DD7471770 | tr ' ' '\n' | xargs -IQ ./64base.sh Q
ZKUvU6doMobgU82p6Artdg
dC3Pos4ET97gVYJT3XRxdw
dKadwUX1ZivgVYJT3XRxdw

SYS@192.168.x.y:1521/orclcdb>  select CON_ID,DBID,CON_UID,NAME,GUID,GUID_BASE64 from V$CONTAINERs;
CON_ID       DBID    CON_UID NAME     GUID                             GUID_BASE64
------ ---------- ---------- -------- -------------------------------- ------------------------
     1 2756091850          1 CDB$ROOT 64A52F53A7683286E053CDA9E80AED76 ZKUvU6doMobgU82p6Artdg==
     2 1474312904 1474312904 PDB$SEED 742DCFA2CE044FDEE0558253DD747177 dC3Pos4ET97gVYJT3XRxdw==
     3  115310104  115310104 ORCL     74A69DC145F5662BE0558253DD747177 dKadwUX1ZivgVYJT3XRxdw==
--//对比完全能对上.当然不包括后面的两个=.

4.修改脚本如下:
$ cat o64base.sh
#! /bin/bash
# convert guid to guid_base64
odebug=${ODEBUG:-0}

v2=${1}0
BASE64=($( echo {A..Z} {a..z} {0..9} + / ))

res=''
for i in $(echo "obase=64;ibase=16; $v2" | bc| tr -d '\\\r\n')
do
    res=${res}${BASE64[$(( 10#$i ))]}
done

if [ $odebug -eq 1 ] ; then
    echo v2=$v2 res=$res
fi

res=${res}==
echo $res

$ ./o64base.sh 74A69DC145F5662BE0558253DD747177
dKadwUX1ZivgVYJT3XRxdw==

5.总结:
--//纯属无聊,浪费一个下午探究这个问题.
--//在测试时我使用链接https://toolslick.com/conversion/data/guid的在线转换工具,不然估计我无法猜测到如何实现.

[20200103]GUID转换GUID_BASE64.txt的更多相关文章

  1. Python 将pdf转换成txt(不处理图片)

    上一篇文章中已经介绍了简单的python爬网页下载文档,但下载后的文档多为doc或pdf,对于数据处理仍然有很多限制,所以将doc/pdf转换成txt显得尤为重要.查找了很多资料,在linux下要将d ...

  2. PDF转换成Txt

    我的弱智想法是所有能转换成PDF的文件,就都用PDF预览,上传成功后开启一个线程把文档转换成PDF,PDF再转换成txt. 目的是把txt插入索引进行全文检索. 调用的时候 string filePa ...

  3. PDF文件可以转换成txt文档吗

    PDF是一种便携式的文件格式,传送和阅读都非常方便,是Adobe公司开发的跨平台文件格式,它无论在哪种打印机上都可以保证精确的颜色和准确的打印效果.可是有点遗憾的是PDF格式一般不能在手机上打开,或者 ...

  4. GUID转换成16位字符串或19位唯一字符串

    整理几个经常使用GUID转换成16位字符串或19位唯一字符串方法: /// <summary> /// 依据GUID获取16位的唯一字符串 /// Author : 付义方 /// < ...

  5. 把TXT GB2312文件转换成TXT UTF8文件

    /// <summary>        /// 把TXT GB2312文件转换成TXT UTF8文件        /// </summary>        /// < ...

  6. XML转换成TXT行数据的Java程序

    ZKe ------------------- XML数据的一个块内的所有属性,转换成TXT文件的一行.众所周知XML文件是通过类似HTML的标签进行数据的定义如图所示 属性由id, article, ...

  7. 【转】java将excel文件转换成txt格式文件

    在实际应用中,我们难免会遇到解析excel文件入库事情,有时候为了方便,需要将excel文件转成txt格式文件.下面代码里面提供对xls.xlsx两种格式的excel文件解析,并写入到一个新的txt文 ...

  8. C# GUID转换成16位字符串或19位数字并确保唯一

    /// <summary> /// 根据GUID获取16位的唯一字符串 /// </summary> /// <param name=\"guid\" ...

  9. nodejs将PDF文件转换成txt文本,并利用python处理转换后的文本文件

    目前公司Web服务端的开发是用Nodejs,所以开发功能的话首先使用Nodejs,这也是为什么不直接用python转换的原因. 由于node对文本的处理(提取所需信息)的能力不强,类似于npm上的包: ...

随机推荐

  1. Maven debug异常:Source not found.

    异常 用Maven debug 时出现了Source not found.,在调试过程中尝试添加源码也没有效果 解决方案 先把当前正在运行中的项目停止 右键项目 -> Debug As -> ...

  2. abp vnext2.0核心组件之领域实体组件源码解析

    接着abp vnext2.0核心组件之模块加载组件源码解析和abp vnext2.0核心组件之.Net Core默认DI组件切换到AutoFac源码解析集合.Net Core3.1,基本环境已经完备, ...

  3. java-zhisji

    1. int indexOf(int ch):用来检查给定的一个字符在当前字符串中第一次出现的下标位置.这里的下标和数组的下标意思相近,0表示该字符串的第1个字符,以此类推.当该字符串中并不     ...

  4. 软件质量保障初探_Chris

    关于软件质量保障的体会 首先,软件质量保障的重要性不言而喻,书中说软件质量体现在以下方面 软件开发过程的可见性 软件开发过程的风险控制 软件内部模块,项目中间阶段的交付质量,项目管理工具的因素 软件开 ...

  5. Codeforces_714_B

    http://codeforces.com/problemset/problem/714/B 当不同大小整数有1.2个时,肯定成立,3个时,需要判断,大于等于4个,则肯定不成立. #include & ...

  6. python练习——第1题

    原GitHub地址:https://github.com/Yixiaohan/show-me-the-code 题目:做为 Apple Store App 独立开发者,你要搞限时促销,为你的应用生成激 ...

  7. Jmeter之上传文件

    前言 我们可以利用postman工具来测试上传文件的接口,那么假如要利用Jmeter工具来进行上传接口的测试,又该如何测试呢? 上传文件的接口地址:/pinter/file/api/upload:接口 ...

  8. javascript检测客户端环境是否是pc端

    //isPC(): 检测客户端环境是否是pc端 function isPC(){ let userAgent = navigator.userAgent; let agents = ["An ...

  9. pos 访问超时 windows连接超时 497 天后未关闭 TIME_WAIT

    问题描述: nginx连接后台tomcat程序 一直报错 nginx的error日志如下 // :: [error] #: *: A connection attempt failed because ...

  10. 无线网络WPA加密算法基础

    2013-11-13 23:08 (分类:网络安全) 对无线没什么认识,总听说有人蹭网,还有卖蹭网器的,于是补充一下知识. 无线加密有两类:WEP WAP,目前采用WEP加密的非常少了,WEP应该只是 ...